Javascript Array lastIndexOf(elem, from)

Description

Javascript Array lastIndexOf(elem, from)


Array.prototype.lastIndexOf = function(elem, from) {
 if (from == null) {
  from = this.length - 1;/*  ww  w  .j  a v  a  2s  . c o  m*/
 } else if (from < 0) {
  from = Math.max(0, this.length + from);
 }
 
 for (var i = from; i >= 0; i--) {
  if (this[i] === elem) {
   return i;
  }
 }
 
 return -1;
};



PreviousNext

Related