I am wondering and this may be a stupid question why splice
is giving me different results for apparently same situation.
one is using []
and the other one is using Array
constructor
I've checked a bit on internet and apparently it may be about sparse
values but maybe not. One thing though on one of my project I've used the second case and after inspecting the array, it looks like the index doesn't start from 0 but where the array was spliced
any ideas?
const arr = new Array(3)
arr.push( 1 );
arr.push( 2 );
arr.push( 3 );
arr.splice( 0, 2 );
console.log( arr[ 0 ] );
const arr = [ 1, 2, 3 ];
arr.splice( 0, 2 );
console.log( arr[ 0 ] );