These are chat archives for FreeCodeCamp/Help

20th
Jan 2019
psyperl
@psyperl
Jan 20 03:21
or being abducted by an old lady
Dw-Develops
@Dw-Develops
Jan 20 04:11
Hello and good evening folks.
it's a blizzard at my house and i'm inside working on code and college.
psyperl
@psyperl
Jan 20 05:10
may the code be with you
Dw-Develops
@Dw-Develops
Jan 20 05:42
Thanks :)
BuntyBru
@BuntyBru
Jan 20 07:57

may the code be with you

hehe

Dw-Develops
@Dw-Develops
Jan 20 08:01
well so far our power and internet have stayed on. That's a definite plus. it can snow all it wants so long as those utilities stay on and I can stay on task.
Niraj Nandish
@Nirajn2311
Jan 20 08:05
@psyperl help me
Niraj Nandish
@Nirajn2311
Jan 20 08:15
@diomed these cats have abducted me
Orxa
@Orcagh_twitter
Jan 20 12:59
I can't reset all codes :/
Jason
@swoopy_gitlab
Jan 20 13:54

how would someone loop through this?

let data = [{prop:val},{prop:val},{prop:val},{prop:val},{prop:val},{prop:val},{prop:val}];

Jason
@swoopy_gitlab
Jan 20 13:59
tried Object.keys it just gave me the indexes?
Aditya
@ezioda004
Jan 20 14:10
@swoopy_gitlab Use for..of
Jason
@swoopy_gitlab
Jan 20 14:14
@ezioda004 inside a loop?
Aditya
@ezioda004
Jan 20 14:16
@swoopy_gitlab Like:
for (let obj of data) {
  console.log(obj);
}
Jason
@swoopy_gitlab
Jan 20 14:24
how would i return them as an array?
@ezioda004
psyperl
@psyperl
Jan 20 14:35
you don't really need to do anything to return them as array? the data is already an array
Jason
@swoopy_gitlab
Jan 20 14:36
@psyperl I got them now, what i really wanted to do is to merge them into one. :)
psyperl
@psyperl
Jan 20 14:36
maybe example of what you expected to be?
Jason
@swoopy_gitlab
Jan 20 14:37
Object.assign(...data)
psyperl
@psyperl
Jan 20 14:39
you confused me lol
I meant how will the data look like, as they are already merged in to one as well
Jason
@swoopy_gitlab
Jan 20 14:41
@psyperl
{ prop:val, prop:val, prop:val, ..and so on }
they were originally
[{prop:val},{prop:val},{prop:val},{prop:val},{prop:val},{prop:val},{prop:val}];
psyperl
@psyperl
Jan 20 14:41
that would be an object, and no you can't do that..
an object can't have the same prop name
Jason
@swoopy_gitlab
Jan 20 14:42
but i just did
psyperl
@psyperl
Jan 20 14:42
lolwut
Jason
@swoopy_gitlab
Jan 20 14:43
ofcourse they don't have the same prop and val. sorry my bad. just written an example poorly
psyperl
@psyperl
Jan 20 14:44
ahh ok
maybe
const data = [{one: 1}, {two: 2}, {three: 3}]
const newData = data.reduce( (b,v) => Object.assign(b,v) ,{})
console.log( newData ) // shoule print {one: 1, two: 2, three: 3}
?
psyperl
@psyperl
Jan 20 14:51
or lol.. you already have the answer with that Object.assign :D
Jason
@swoopy_gitlab
Jan 20 14:51
yea :)
psyperl
@psyperl
Jan 20 14:51
awesome
Jason
@swoopy_gitlab
Jan 20 14:53
used the spread ... as i don't know how many objects will there be
May Kittens Devour Your Soul
@diomed
Jan 20 16:48
@ezioda004 whisper me sexy js things
(butter ... bread)
psyperl
@psyperl
Jan 20 18:02
const legs = [{cows: 4}, {chicken:2}, {birds: 2}]
Levis
@agabyte
Jan 20 20:31
If you're using Firefox and working on Introduction to Data Visualizations with D3 Challenges make sure to check Allow pages to choose their own fonts, instead of your selections above. under Fonts & Colors in firefox preferences :tired_face: