var array = [{"one":1, "two":2},{"one":3, "two":4}];
var result = array.findIndex(function (value) {
if (value === 2) {
return false;
}
return true;
});
console.log(result);
i keep getting '0' in the console. how should i change (value ===2) ? i have tried change to (value === {"two":2}) but still return '0'.
is there any other array method that suitable ?
You need to check one of the properties of the objects of the array. Then return the result of the check.
var array = [{ one: 1, two: 2 }, { one: 3, two: 4 }],
result = array.findIndex(function(object) {
return object.two === 2;
});
console.log(result);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With