var arrayObj = [{name:"bull", text: "sour"}, { name: "tom", text: "tasty" }, { name: "tom", text: "tasty" } ] var index = arrayObj.findIndex(x => x.name=="bob"); // here you can check specific property for an object whether it exist in your array or not index === -1 ? arrayObj.push({your_object}) : console.log("object already exists")
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter