Nodejs Array Last Index lastIndexOf(value, begin, strict)

Here you can find the source of lastIndexOf(value, begin, strict)

Method Source Code

/**// w ww.j av a  2s  .c  om
 * insert is a method of Array to get index of the last element that matches value
 *
 * @param value       a Object (String, Number, ...), element to search index
 * @param begin       a Number, index where begin of search
 * @param strict      a Boolean, if search is strict (Optional)
 * @return            a Array, the array with the element inserted;
 */
Array.prototype.lastIndexOf = function(value, begin, strict)
{
  begin = +begin || 0;
  var i = this.length;
  while(i-- > begin)
  {
    if(this[i] === value || strict && this[i] == value )
    {
      return i;
    }
  }
  return -1;
};

Related

  1. lastIndexOf(elt /*, from*/)
    Array.prototype.lastIndexOf = Array.prototype.lastIndexOf || function(elt )  {
        var len = this.length;
        var from = Number(arguments[1]);
        if (isNaN(from)) {
            from = len - 1;
        } else {
            from = (from < 0)
                ? Math.ceil(from)
                : Math.floor(from);
    ...
    
  2. lastIndexOf(item)
    Array.prototype.lastIndexOf = function(item){
      var lastIndex = -1;
      for (var i=0; i<this.length; i++){
        if (this[i] === item){
          lastIndex = i;
      return lastIndex;
    
  3. lastIndexOf(o)
    Array.prototype.lastIndexOf = function (o) {
        var index = this.length;
        for (; index >= 0; index--) {
            if (index in this && this[index] === o)
                return index;
        return -1;
    };
    
  4. lastIndexOf(searchElement, fromIndex)
    Array.prototype.lastIndexOf = function(searchElement, fromIndex) {
      if (!fromIndex || !isFinite(fromIndex)) {
        fromIndex = this.length - 1;
      for (var i = fromIndex; i >= 0; --i) {
        if (this.hasOwnProperty(i) && this[i] === searchElement) {
          return i;
      return -1;
    
  5. lastIndexOf(v,b)
    Array.prototype.lastIndexOf = function(v,b){
        var idx=-1;
      if(b===true && typeof(v)=="function"){
        for (var i=this.length-1;i>=0;i--) {
          if(v(this[i])){idx=i; break;}
      } else {
        for (var i=this.length-1;i>=0;i--) {
          if(this[i]===v){idx=i; break;}
    ...