I need to know the best method to check if the value is in the array before push it
I have an array :
coordinates: [
{x: 160, y: 160},
{x: 192, y: 160},
{x: 224, y: 160},
{x: 224, y: 192},
];
For each call of my function , I need to check if new coordinates is it before proceed to push.
const payload= {x: 224, y: 190}
//Next function call
const payload = {x: 224, y: 190} // need to refuse pushing this value
I tried filter and other JS methods without success.
for example:
coordinates.filter(c => {if(payload !== c){coordinates.push(new)});
This one doesn't work for me .