let arr1 = [1, -2, 3, 4];
let arr2 = [8, 3, -8, 1];
function fun()
{
console.log(arguments)
}
const fun1 = (...n) =>{
console.log(n)
}
fun.call(...arr1, ...arr2)
output : [object Arguments] { 0: -2, 1: 3, 2: 4, 3: 8, 4: 3, 5: -8, 6: 1 }
fun1.call(...arr1,...arr2)
output : [-2, 3, 4, 8, 3, -8, 1]
arr1 and arr2 combined have 8 values but output is only 7 values why? how to get all the values ?
Because you've used
Function.prototype.callto callfun, and the first argument tocallisn't an argument to pass tofun, it's the value to use asthisduring the call. So that first value doesn't show up in the argumentsfunsees (it's the value ofthisinstead, wrapped in an object wrapper if this is loose mode code).There's no reason to use
fun.callin your example, just:but if you needed to us
callfor some reason, you'd specify a different first argument (to use asthisduring the call):(Side note: In modern JavaScript, there's almost never any reason to use the
argumentspseudo-array. Use a rest parameter instead, which gives you a true array.)With those changes: