This might be a duplicate but I could not help but post this, I have an array with this format
answerCollection= {
0:
{selected : a,
status : false
},
1:
{selected : a,
status : false
}
}
I want to do an index check on the this aray like this
if(answerCollection.indexOf(indexNo) == -1){
sel = "a";
}
but it keeps failing i.e. I keep getting a return value of -1, irrespectively of if the index exist in the array or not.
How do I do this kind of search?
answerCollectionis a plain object instead of array. Also, the argument forindexOfis the value and not the key.if (!answerCollection[indexNo]) { ... }?