0

Can someone please point out what I am misunderstanding about apply. I have the following code:

function testFunc(input) {
  console.log(Array.isArray(input));
  console.log(input);
}

var obj = {};
var testArr = ["test1", true, 3];

testFunc(testArr);  // first call

testFunc.call(obj, testArr);  // second call

testFunc.apply(obj, testArr);  // third call

As expected, the first and second calls produce the outputs

true and Array["test1", true, 3].

From my understanding of all that I've read on apply, the third call should also produce the same: apply is expecting this (obj) and an array-like argument.

However what I get is

false and test1 (as a string).

How and why is the array being collapsed to its first element? What gives?

Thanks

Community
  • 1
  • 1

0 Answers0