Javascript Array indexOf(val)

Description

Javascript Array indexOf(val)


// challenge3/challenge.js

Array.prototype.indexOf = function(val) {
  
  // Student code below
  for (var i = 0; i < this.length; i++) {
    if (this[i] === val) {
      return i//w  w  w  .  j a  v a 2s . c o m
    }
  }
  return -1
}

Javascript Array indexOf(val)

Array.prototype.indexOf = function(val) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == val) return i;
    }/*from  w  ww .  j  a v a 2 s  .c  o  m*/
    return -1;
};

Javascript Array indexOf(val)

Array.prototype.indexOf = function(val){
  var arrayVal = this;

  for(var i = 0 ; i < arrayVal.length; i++){
    if(arrayVal[i] == val){
      return 4;/*from  w ww  . ja v a 2s .  c  o  m*/
    }
  }

  return -1;
}

Javascript Array indexOf(val)

"use strict";/*from www . ja  va  2 s.  c o m*/
Array.prototype.indexOf = function(val) {
  for (var i = 0; i < this.length; i++) {
    if (this[i] == val) return i;
  }
  return -1;
};

Javascript Array indexOf(val)

var reg2 = /(\(\-)|[\+\-]/g;
var x = '5x^(-2)-6x^2+8x-6x+7-6x^(-7)';
var m = x.match(reg1);
var n = x.match(reg2);
Array.prototype.indexOf = function(val) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == val) return i;
    }/* ww w.j a v a 2 s. c  om*/
    return -1;
};
Array.prototype.remove = function(val) {
    var index = this.indexOf(val);
    while (index > -1) {
        this.splice(index, 1);
       index = this.indexOf(val);
    }
};
var o = 0;
n.remove('(-');
console.log(m);
console.log(n);

Javascript Array indexOf(val)

Array.prototype.indexOf= function (val) {
    for(var i=0;i<this.length;i++){
        if(this[i]==val) return i;
    }//from   w w w  .j  av  a2  s . c  o m
    return -1;
};
Array.prototype.remove= function (val) {
    var index=this.indexOf(val);
    if(index>-1){
        this.splice(index,1);
    }
};
Object.size = function(obj) {
    var size = 0, key;
    for (key in obj) {
        if (obj.hasOwnProperty(key)) size++;
    }
    return size;
};



PreviousNext

Related