Javascript Array trim(value)

Description

Javascript Array trim(value)



Array.prototype.trim = function (value) {
 var array = this.slice(0); // Don't modify this, return new array.

 while (array.length > 0 && array[0] === value) {
  array.shift();/*  w  w w  .  ja v  a2s  .  c o m*/
 }

 while (array.length > 0 && array[array.length - 1] === value) {
  array.pop();
 }

 return array;
};



PreviousNext

Related