Get array index from value - Node.js Array

Node.js examples for Array:Search

Description

Get array index from value

Demo Code

/**// w w w  .j  a  v  a 2  s  .c  om
 * Get array index from value
 * (Function from Turboid.js)
 */ 
Array.prototype.getIndex = function(value) {
  for(var i=0; i<this.length; i++) {
    if(this[i]==value) {
      return i;
      break;
    }
  }
  return null;
}

Related Tutorials