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
  • 274,122
  • 60
  • 696
  • 724
Alex Safayan
  • 2,921
  • 4
  • 17
  • 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
  • 11,574
  • 3
  • 35
  • 48
  • 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