With the following array:
randomArray = [
{alias: 'book1', page: 127},
{alias: 'book1', page: 115},
{alias: 'book2', page: 115}
]
If I'd like to add an object to the array, (when order doesn't matter), I'm assuming I can simply:
randomArray.push({alias: 'book3', page: 303})
But if I want to remove an object, say for example I would like to remove:
{alias: 'book1', page: 115}
, how would I do this?
I've seen other stack overflow questions, like this, try to find an index of the object, but they look for one property assuming that property has unique values throughout the array.
My thought:
I wanted to try indexOf
and then splice
that object, but it doesn't work.
randomArray.indexOf({alias: 'book1', page: 115})
returns -1
What's an efficient way to look through an array of objects and remove an exact match? For clarity, without using a library, and all of these objects will have the same alias
and id
properties, no more, no less. (Also, am I supposed to call these properties or keys, or are they synonymous?)
Edit: I've changed id
to page
to make more sense