In this particular scenario, the output varies depending on the first argument passed to apply
The snippet of code looks like this:
var fruitarray = [];
fruitarray[0] = ['strawberry', 'orange'];
fruitarray[1] = ['lime', 'peach', 'banana'];
fruitarray[2] = ['tangerine', 'apricot'];
var array1= fruitarray.concat.apply([], fruitarray); // array1 becomes 'tangerine'
var array2= fruitarray.concat.apply('undefined', fruitarray); // array2 becomes 'banana'
var array3= fruitarray.concat.apply(fruitarray , fruitarray); // array3 becomes 'lime'
var array4= fruitarray.concat.apply(this, fruitarray); // array4 becomes 'banana'
What could be the reason behind this?
**** EDIT: *****
Apologies!!!
Here is the corrected code:
var fruitarray = [];
fruitarray[0] = ['strawberry', 'orange'];
fruitarray[1] = ['lime', 'peach', 'banana'];
fruitarray[2] = ['tangerine', 'apricot'];
var array1= fruitarray.concat.apply([], fruitarray);
console.log(array1[5]); // 'tangerine'
var array2= fruitarray.concat.apply('undefined', fruitarray);
console.log(array2[5]); // 'banana'
var array3= fruitarray.concat.apply(fruitarray , fruitarray);
console.log(array3[5]); // 'lime'
var array4= fruitarray.concat.apply(this, fruitarray);
console.log(array4[5]); // 'banana'
I am currently using Firebug 2.0.9 for testing (Firefox)