const a = ['1', '2', '3']; const i = 5; a[i] = '4'; console.log(a); // (6) [ "1", "2", "3", empty x 2, "4" ] // Array(6) [ "1", "2", "3", <2 empty slots>, "4" ] a[i - 1] = undefined; console.log(a); // (6) [ "1", "2", "3", empty, undefined, "4" ] // Array(6) [ "1", "2", "3", <1 empty slot>, undefined, "4" ] console.log(a.hasOwnProperty(i - 2)); // empty → false console.log(a.hasOwnProperty(i - 1)); // undefined → true
empty is a pseudo value used to represent a hole in an array.
empty
hole
ECMAScript 6: holes in Arrays Elements kinds in V8
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
5a. Using index position
emptyis a pseudo value used to represent aholein an array.ECMAScript 6: holes in Arrays
Elements kinds in V8