Question : array has object with property js
Answered by : braden
myArray.some(obj => obj.property === 'value')
// returns true or false
Source : https://stackoverflow.com/questions/8217419/how-to-determine-if-javascript-array-contains-an-object-with-an-attribute-that-e | Last Update : Fri, 12 Mar 21
Question : javascript include property array object
Answered by : restu-wahyu-saputra
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
})
Source : | Last Update : Fri, 30 Jul 21