There are two main approaches
- splice()
- delete
splice() : splice is the most conman approaches remove a specific item from
an array using JavaScript
syntax : MyArray.splice(index, 1);
let country = ['USA', 'UK', 'UAE', 'India']
let removed = country.splice(2, 1);
Result : ['USA', 'UK', 'India']
delete : Delete is second way to remove an item from an array in JavaScript,
syntax: delete MyArray[index]
let country1 = ['USA', 'UK', 'UAE', 'India']
let removed = delete country1[2]
Result : ['USA', 'UK', undefined , 'India']
Better to use splice() it is simple way to remove a specific item from an array using
JavaScript , when you use delete for an array you could get wrong results
for MyArray.length
Here
country1.length = 4
country.length = 3