Answer by Nasser Torabzade for Finding field.value in JSON array

you can do it with a simple function, no third party modules needed:

var x = [{ a: 1, b: 2}, { a: 11, b: 12}, { a: 31, b: 23}, { a: 51, b: 24}];

function getIndexOf(value){
    for(var i=0; i<x.lengh; i++){
        if(x[i].a == value)
            return i;
    }
}

alert(getIndexOf(value)); // output is: 1

Leave a Reply

Your email address will not be published. Required fields are marked *