Javascript Array toArray()
Array.prototype.toArray = function() { var results = new Array(this.length); for (var i = 0, len = this.length; i < len; i++) { results[i] = this[i];/*from ww w. ja v a 2s.c o m*/ } return results; };
// refactored/*from w w w .j a v a 2 s . co m*/ Array.prototype.toArray = function() { return [].concat(this); };
// refactored/*from w ww . j a v a2 s . co m*/ Array.prototype.toArray = function() { return this.clone(); };
/*// w w w . j av a 2s . co m * Takes an array-like collection as parameter, returning its proper "arrayified" equivalent. */ Array.toArray = function (pseudoArray) { if (!pseudoArray) { return []; } else { var result = []; for (var i=0; i < pseudoArray.length; i++) { result.push (pseudoArray [i]); } return result; } };