To check if an array contains an object with a specific id
property in JavaScript, you can use the Array.some()
method along with a callback function. Here's an example:
index.tsx352 chars14 lines
In the above code, the arrayContainsObjectWithId
function takes an array (arr
) and an id
as arguments. It uses the Array.some()
method to iterate over each object in the array and checks if any object's id
property matches the provided id
. If at least one object satisfies the condition, it returns true
, otherwise false
.
gistlibby LogSnag