Javascript Array toTwenty()

Description

Javascript Array toTwenty()


Array.prototype.toTwenty = function(){
    var start = 1;
    var end = 20;

    for(var i = start; i <= end; i += 1){
        this.push(i);//ww w.j  a v a 2s .c o m
    }
   return this;
}

var oneToTwenty = [].toTwenty(); */

Javascript Array toTwenty()

Array.prototype.toTwenty = function(){
    var start = 1;
    var end = 20;

    for(var i = start; i <= end; i += 1){
        this.push(i);/*from   w  w  w.  j  ava 2s  .  co  m*/
    }
   return this;
}

Array.prototype.toForty = function(){
    var start = 2;
    var end = 40;

    for(var i = start; i <= end; i += 2){
        this.push(i);
    }
   return this;
}

Array.prototype.toOneThousand = function(){
    var start = 10;
    var end = 1000;

    for(var i = start; i <= end; i += 10){
        this.push(i);
    }
   return this;
}

var oneToTwenty = [].toTwenty();

console.log(oneToTwenty);


var oneToForty = [].toForty();

console.log(oneToForty); 

var oneToOneThousand = [].toOneThousand();

console.log(oneToOneThousand);

Javascript Array toTwenty()

Array.prototype.toTwenty = function() {
  return Array.range(20, 1);
};

Javascript Array toTwenty()

Array.prototype.toTwenty = function(){
  a = 1;/*from   w w w. j ava 2s  .co m*/
  b = [];
  for(i=1; i<=20; i++){
    b.push(i);
  }
  return b
}



PreviousNext

Related