I am having a data with multiple options, of which only one will be having the value correct
to be true
. I need to find the index of this particular data. I have achieved it with the below code. But however I want to know if there are any performance implication for this method and if there is any better method when I am using Angular Js.
var data = [
{"option": "8", "correct": false},
{"option": "14", "correct": false},
{"option": "10", "correct": true},
{"option": "23", "correct": false}
];
var i = data.length;
while(i--) {
if (data[i].correct == true){
alert("Option:"+ data[i].option + " Index:"+ i);
break;
}
}