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
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.
0
Use this function
function addToCollection( title, artist, year){
collection.push({title, artist, year});
}
https://code.sololearn.com/W6nM358Addm9/?ref=app