javascript - Array.push() if does not exist? - Stack Overflow

PHOTO EMBED

Tue Feb 09 2021 12:59:48 GMT+0000 (Coordinated Universal Time)

Saved by @ozgunn #javascript

var item = {name: "tom", text: "tasty"}
var array = [{}]
if (!array.find(o => o.name === 'tom' && o.text === 'tasty'))
    array.push(item)
content_copyCOPY

https://stackoverflow.com/questions/1988349/array-push-if-does-not-exist