0

Pushing new objects into an empty array with a function

So i'm working on a project. A system to handle data for a record store. //say i have the variable set to an empty array let collection = [] //Then a function called function addToCollection( title, artist, year){ } // that when called on, creates a new object called record and pushes it into the array. I can't get the syntax correct to return the array with the record object in it correct via console.log //HELP PLEASE

13th Apr 2019, 5:39 PM
Cory
Cory - avatar
2 Answers
+ 3
Do you issues with pushing objects to the array? collection.push(new record())?? And actually console.log won't print the object properties, which you might have expected, on its own by just writing something like console.log(collection) Rather it'll log something like [object, object, object,...]. To check objects properties, yiu need to log them explicitly.
13th Apr 2019, 5:53 PM
ŠØŠ°Ń‰Šø Š Š°Š½Š¶Š°Š½
ŠØŠ°Ń‰Šø Š Š°Š½Š¶Š°Š½ - avatar
0
Use this function function addToCollection( title, artist, year){ collection.push({title, artist, year}); } https://code.sololearn.com/W6nM358Addm9/?ref=app
14th Apr 2019, 2:43 AM
CalviÕ²
CalviÕ² - avatar