I have one array in JavaScript:
['html', 'css', 'perl', 'c', 'java', 'javascript']
How can I delete "perl" element?
There has to be removing the third element. It must be to remove the element with a value of "perl".
Answer
Find the index of the word, then use splice to remove it from your array.
var array = ['html', 'css', 'perl', 'c', 'java', 'javascript']
var index = array.indexOf('perl');
if (index > -1) {
array.splice(index, 1);
}
No comments:
Post a Comment