Find array element index - Node.js Array

Node.js examples for Array:Search

Description

Find array element index

Demo Code


exports.findIndex = function(arr, id) {
    var len = arr.length;

    while (len--) {
        if (arr[len].id === id) {
            return len;
        }//from  www.j av a2 s. co  m
    }

    return -1;
};

Related Tutorials