2

Say I have a array

var arrayName = []; 

with three items

arrayName = ['hi', 'hey', 'hello'];

how do I delete the item 'hey' from the array?

Sotirios Delimanolis
  • 252,278
  • 54
  • 635
  • 683
Alex
  • 2,571
  • 4
  • 13
  • 22

1 Answers1

0
var hey = arrayName.splice(1,1);

EDIT: If you would prefer to get the index of a particular value, you can use:

arrayName.indexOf("hey");
maiorano84
  • 10,680
  • 3
  • 31
  • 46
  • deleting just changes the value, it doesn't remove the array item or affect the .length unless you do the last one... – dandavis Sep 10 '14 at 01:44
  • @dandavis - Derp! You're right. I keep assuming the delete keyword affects objects and arrays the same way. Edited. – maiorano84 Sep 10 '14 at 01:50