I am new to constructing a JavaScript Array prototype. Please only paste previous links that are directly appropriate as I have been sourcing on SO and on w3school. https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype
I would like to create a method for an array that checks if the 'id' field within the object does not already exist in the array. If not, then 'push' object into the array, else do nothing.
Each object has a unique 'id' field.
eg
var array = [{ id: 001, title: 'some title'},
{ id: 002, title: 'other title'}]
var object = {id: 001, title: 'some title'}
// if object.id does not exist in array...
array.push(object)
//else do nothing
I would like the function to take the 'id' field as an argument so this function has wider use.
Are there any drawbacks to extending the array.Prototype? Otherwise I can do a for loop instead to do the check without the prototype constructor.