Answers for "Check if an array contains an object with a certain property value in JavaScript?"

2

Check if an array contains an object with a certain property value in JavaScript?

//If you need to modify the existing Array, you should use splice().

for (var i = array.length - 1; i > -1; i--) {
    if (array[i].name === "zipCode")
        array.splice(i, 1);
}
//Notice that I'm looping in reverse. This is in order to deal with the fact that when
//you do a .splice(i, 1), the array will be reindexed.

//If we did a forward loop, we would also need to adjust i whenever we do a .splice()
//in order to avoid skipping an index.
Posted by: Guest on October-21-2021
-1

array has object with property js

myArray.some(obj => obj.property === 'value')
// returns true or false
Posted by: Guest on March-05-2021
-1

check if property has value in array javascript

const magenicVendorExists =  vendors.reduce((accumulator, vendor) => (accumulator||vendor.Name === "Magenic"), false);
Posted by: Guest on November-05-2020

Code answers related to "Check if an array contains an object with a certain property value in JavaScript?"

Code answers related to "Javascript"

Browse Popular Code Answers by Language