Find index of particular value within an array - Node.js Array

Node.js examples for Array:Search

Description

Find index of particular value within an array

Demo Code

/**// ww w.  jav a  2 s. c  o  m
 * find index of particular value within an array
 *
 * @param {String} query
 *          the value to search for within array
 *
 * @return {Number} index of object within array
 *
 */
Array.prototype.findIndex = function(query) {
    for (var i=this.length-1; i>=0; i--) {
        if (this[i].toLowerCase() === query.toLowerCase()) {
            break;
        }
    }
    return i;
};

Related Tutorials