Arrays have a 0-based index. This means each item in the array has its unique index number and the index of the first item will always be 0. However, a point to be noted here is that the index of an item may or may not change depending upon the kind of mutation.
From the above details, it is clear that if you know the index number of an item, you can modify its value or completely remove it from the array. There are various methods to modify an array. Since we just want to remove an item, we will make use of the delete operator.
In the following example, we have a global variable users and that holds an array. In the input element, we will enter a user name and try to find the index of it in the array. Then, we will use that index to remove that element from the array. Please have a look over the code example and steps given below.
HTML & CSS
We have 4 elements in the HTML file (div, button, input, and ul). The div element is just a wrapper for the rest of the elements.
The inner text for the button element is “Remove”.
We have done some basic styling using CSS and added the link to our style.css stylesheet inside the head element.