Wouldn't it be nice if we can find out if at least one object with specific caracteristics (properties) is included inside an array.
Like Array.includes(item) we can use to discover if an element currently exists inside an array, we would be able to determine if an object with specific catacteristics is listed inside the array.
The point is that every time I need to investigate an array of objects if a specific object containing specific properties I use the Array.findIndex(obj => obj.a === object.a && obj.b === object.b && ...) !== -1.
I would propose someting like this:
Array.exists({...object.properties})
The exists()
method checks if one elements in an array has the properties with specified values.
The exists() method executes the function once for each element present in the array:
- If it finds an array element where the object matches values, exists() returns true (and does not check the remaining values)
- Otherwise it returns false