These are chat archives for FreeCodeCamp/Help

20th
Jan 2019
psyperl
@psyperl
Jan 20 03:21 UTC
or being abducted by an old lady
Dw-Develops
@Dw-Develops
Jan 20 04:11 UTC
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 UTC
may the code be with you
Dw-Develops
@Dw-Develops
Jan 20 05:42 UTC
Thanks :)
BuntyBru
@BuntyBru
Jan 20 07:57 UTC

may the code be with you

hehe

Dw-Develops
@Dw-Develops
Jan 20 08:01 UTC
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 UTC
@psyperl help me
Niraj Nandish
@Nirajn2311
Jan 20 08:15 UTC
@diomed these cats have abducted me
Orxa
@Orcagh_twitter
Jan 20 12:59 UTC
I can't reset all codes :/
Jason
@swoopy_gitlab
Jan 20 13:54 UTC

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 UTC
tried Object.keys it just gave me the indexes?
Aditya
@ezioda004
Jan 20 14:10 UTC
@swoopy_gitlab Use for..of
Jason
@swoopy_gitlab
Jan 20 14:14 UTC
@ezioda004 inside a loop?
Aditya
@ezioda004
Jan 20 14:16 UTC
@swoopy_gitlab Like:
for (let obj of data) {
  console.log(obj);
}
Jason
@swoopy_gitlab
Jan 20 14:24 UTC
how would i return them as an array?
@ezioda004
psyperl
@psyperl
Jan 20 14:35 UTC
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 UTC
@psyperl I got them now, what i really wanted to do is to merge them into one. :)
psyperl
@psyperl
Jan 20 14:36 UTC
maybe example of what you expected to be?
Jason
@swoopy_gitlab
Jan 20 14:37 UTC
Object.assign(...data)
psyperl
@psyperl
Jan 20 14:39 UTC
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 UTC
@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 UTC
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 UTC
but i just did
psyperl
@psyperl
Jan 20 14:42 UTC
lolwut
Jason
@swoopy_gitlab
Jan 20 14:43 UTC
ofcourse they don't have the same prop and val. sorry my bad. just written an example poorly
psyperl
@psyperl
Jan 20 14:44 UTC
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 UTC
or lol.. you already have the answer with that Object.assign :D
Jason
@swoopy_gitlab
Jan 20 14:51 UTC
yea :)
psyperl
@psyperl
Jan 20 14:51 UTC
awesome
Jason
@swoopy_gitlab
Jan 20 14:53 UTC
used the spread ... as i don't know how many objects will there be
May Kittens Devour Your Soul
@diomed
Jan 20 16:48 UTC
@ezioda004 whisper me sexy js things
(butter ... bread)
psyperl
@psyperl
Jan 20 18:02 UTC
const legs = [{cows: 4}, {chicken:2}, {birds: 2}]
Levis
@agabyte
Jan 20 20:31 UTC
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: