dddeee dddeee - 2 months ago 8
Javascript Question

([ numbers ], numbers) as function parameter, how to get numbers from outside of [ ]?

function a(b) {

var array = Array.prototype.slice.call(b);
console.log(array);

var array_two = ???;
console.log(array_two);

}

a([1, 2, 3], 1, 2);


console.log(array);
gives me output
[1, 2, 3]
as expected.

What I want to achieve here is getting
[1, 2]
- numbers after [ ], joined as array. I thought that
b[number]
would solve the problem.
b[0]
- array,
b[1]
- first number after array,
b[2]
- second number after array but apparently it does not work like that. Do you know any solution for that?

Answer

you can either change your function to

function a(array,firstArgAfterArray,secondArgAfterArray)

or you can get the first and seconds args after the array like that

arguments[1] , arguments[2]