Nodejs Array Index indexOf(value, begin, strict)

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

Method Source Code

/**/*from   w  w  w.  j  a  va2  s  . c  om*/
 * indexOf is a method of Array  to get the index of first element in the Array
 *
 * @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 Number, index of the first element that matches value if exist else -1
 */
Array.prototype.indexOf = function(value, begin, strict)
{
  for(var i = +begin || 0; i < this.length; i++)
  {
    if(this[i] === value || strict && this[i] == value)
    {
      return i;
    }
  }
  return -1;
};

Related

  1. indexOf(val)
    Array.prototype.indexOf = function(val){
      var arrayVal = this;
      for(var i = 0 ; i < arrayVal.length; i++){
        if(arrayVal[i] == val){
          return 4;
      return -1;
    
  2. indexOf(val)
    Array.prototype.indexOf = function(val) {
        for (let i = 0; i < this.length; i++) {
            if (this[i] == val) return i;
        return -1;
    };
    
  3. indexOf(value)
    Array.prototype.indexOf = function(value) {
      for (var i = 0; i < this.length; i++) {
        if (this[i] == value) {
          return index = i;
      return -1;
    };
    
  4. indexOf(value)
    Array.prototype.indexOf = function(value) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] === value) {
                return i;
    
  5. indexOf(value)
    Array.prototype.indexOf = function (value) {  
      for(var i=0; i<this.length; i++) {
        if(this[i] === value) {
          return i;
      return -1;
    
  6. indexOf(what, i)
    Array.prototype.indexOf = function(what, i) {
            i = i || 0;
            var L = this.length;
            while (i < L) {
                if(this[i] === what) return i;
                ++i;
            return -1;
        };
    ...
    
  7. index(val)
    Array.prototype.index = function(val) {
      for(var i = 0, l = this.length; i < l; i++) {
        if(this[i] == val) return i;
      return null;
    };
    
  8. index(val)
    "use strict";
    Array.prototype.index = function(val) {
      for(var i = 0, l = this.length; i < l; i++) {
        if(this[i] == val) return i;
      return null;
    };
    
  9. indexOfAttr(attr, value)
    Array.prototype.indexOfAttr = function (attr, value) {
        for(var i = 0; i < this.length; i += 1) {
            if(this[i][attr] === value) {
                return i;
        return -1;
    };