Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript: why need to delete the 0 index of an array

in underscore source code, after applying shift or splice on an array and in case the length of the array is zero :

 if ((name == 'shift' || name == 'splice') && obj.length === 0) delete obj[0];

any idea why still need to do this : delete obj[0]

like image 722
vancewang Avatar asked Mar 19 '23 01:03

vancewang


1 Answers

Searching around in the Issue tracker shows that my assumption was right, it is just a fix for an IE bug.

IE bugs with splice() and shift():

jdalton commented on 6 Dec 2011
IE bugs with splice() and shift(), failing to remove the 0 indexed value, when using an array-like-object with _(...).
IE compatibility mode and IE < 9 have buggy Array shift() and splice() functions that fail to remove the last element, object[0], of array-like-objects even though the length property is set to 0.

like image 166
t.niese Avatar answered Apr 01 '23 08:04

t.niese