Wouldn’t it be great if there was an easy way to remove an element from an array?
If you don’t know how to do it, you can follow along with this tutorial.
The delete operator is used to remove the value or property of an object or array.
A task object has four properties (id, description, status, deadline). Now, delete the deadline from the task object.
Note: It's fit for deleting object properties because when you use it for an array, the array's length will not be affected. Because, in that case, it will replace the element with undefined.
The splice method replaces or removes existing elements from an array. It returns an array of deleted values.
A platforms array has three elements (udemy, eduonix, skillshare). Now, start deleting elements from index 1.
It removes the last element from an array and returns the deleted element in form of a string. If the array is empty undefined will return.
A roles array has three elements (developers, designer, marketer). Now, delete the last array element.
It removes the first element from an array and returns it.
A names array has three elements (John, Edward, Jack). Now, delete the first array element.
It's a programmatical way to delete a specific element from an array.
Just like you get filtered water from the filtration plant, same like that you get the new purified array by ignoring the elements you desire.
A tasks array has four objects with a unique identity for each object. Now, delete the task which has an id of 3.