I understand the commands needed to add an object to an array. I know its array.push(object)
.
However, say I have this array of objects:
const artists = [{
"rank": 1,
"name": "Rakim",
"year": 1985,
"album": "Paid in Full",
},
{
"rank": 2,
"name": "Nas",
"year": 1994,
"album": "Illmatic"
}
]
If i needed to add a new one with a function. How would I do so? And i want to make it a function that would allow me to add more than one in the future.
So something like,
function addArtist(array {}) {
return array;
}
console.log(addArtist(array {
new object here
}));