I am creating a project using Angular. During the development, I am facing a problem when pushing values to my array. My requirement is that I want to push the value to the array unless the value already exists in the array. If it already exists, then simply replace that value with newer value.
This is my code, which is currently not working:
var obj = {
   question_id: "1",
   id: "2",
   "question": "This is a test"
};
This is the object that I want to push:
this.selectedOptions = [];
if (!this.selectedOptions.some(function(entry) { return entry.question_id === category.question_id;})) {
    this.selectedOptions.push(category);
}



this.selectedOptions? Add it to your questionthis.selectedOptions = []? You need to post what the structure of objects inside that array is