Languages
[Edit]
EN

JavaScript - array delete operator vs splice method

0 points
Created by:
Jan-Alfaro
681

In this article, we would like to show you the difference between delete operator and splice method on array elements in JavaScript.

1. delete operator

Edit

The delete operator will remove the object property, but won't reindex the array or change its length. This makes the element appears as if it was undefined.

Note:

The value is not in fact set to undefined. The property is removed from the array, making it appear undefined.

In the Google Chrome developer tools we can see the following output:

or in Node.js:

2. splice() method

Edit

The array.splice(start, deleteCount) actually removes the element, reindexes the array, and changes its length.

 

References

Edit
  1. delete operator - JavaScript | MDN
  2. Array.prototype.splice() - JavaScript | MDN

Alternative titles

  1. JavaScript - array delete element vs splice
  2. JavaScript - difference between array delete and splice
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join