delete vs splice javascript
/*
Delete: removes the object from the element in the array, the length of the
array won't change.
Splice: removes the object and shortens the array.
*/
// Using delete
arr = ['a', 'b', 'c', 'd'];
delete arr[0];
console.log(arr); // [empty, "b", "c", "d"]
// Using splice
arr = ['a', 'b', 'c', 'd'];
arr.splice(0, 1); // deletes 'a' from arr
console.log(arr); // ['b', 'c', 'd']
Are there any code examples left?
New code examples in category Javascript