myArray.some(obj => obj.property === 'value')
// returns true or false
const data = [{ name: 'dendi', age: 23 }, { name: 'dhani' }]
const result = data.filter((v, i) => {
if (!Object.keys(v).includes('age')) {
Object.defineProperty(v, 'age', {
value: 25,
writeable: true,
enumerable: true
})
}
return v
})
//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.