How to create an array from function arguments using Array.prototype.slice() in JavaScript

2 Answers

0 votes
function f() {
  return Array.prototype.slice.call(arguments);
}

var arr = f(1, 2, 3, 4);

document.write(arr); 
 
/*
run:  

1,2,3,4 
 
*/

 



answered May 20, 2016 by avibootz
0 votes
var aps = Array.prototype.slice;
var slice = Function.prototype.call.bind(aps);

function f() {
  return slice(arguments);
}

var arr = f(1, 2, 3, 4);

document.write(arr); 
 
/*
run:  

1,2,3,4 
 
*/

 



answered May 20, 2016 by avibootz
...