Skip to content Skip to sidebar Skip to footer

FindIndex() Javascript Array Object

var array = [{'one':1, 'two':2},{'one':3, 'two':4}]; var result = array.findIndex(function (value) { if (value === 2) { return fal

Solution 1:

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);

Solution 2:

Its first argument of the array .change with value.two .its object property not a array

var array = [{"one":1, "two":2},{"one":3, "two":4}];
            var result = array.findIndex(function (value) {
                               return value.two == 2;
            });
            console.log(result); 

Post a Comment for "FindIndex() Javascript Array Object"