Javascript Array map(callback, scope)

Description

Javascript Array map(callback, scope)


// Array.prototype.map
Array.prototype.map = function map(callback, scope) {
  for (var array = this, arrayB = [], index = 0, length = array.length, element; index < length; ++index) {
    element = array[index];/*w w w .jav a2  s . c  o  m*/

    arrayB.push(callback.call(scope || window, array[index], index, array));
  }

  return arrayB;
};

Javascript Array map(callback, scope)

// Array.prototype.map
Array.prototype.map = function map(callback, scope) {
 for (var array = this, arrayB = [], index = 0, length = array.length, element; index < length; ++index) {
  element = array[index];//from w  ww.j  av  a  2s  .c  o m

  arrayB.push(callback.call(scope || window, array[index], index, array));
 }

 return arrayB;
};



PreviousNext

Related