0

can you please tell me how to how to delete value from array using jquery ?.I am able to delete values But in place of value I am getting undefined value.

items = ['a', 'b', 'c', 'd'];
if(items.indexOf('c') !== -1) {
  delete items[items.indexOf('c')];
}
console.log(items)
alert(items)
alert(items.length)

It is printing 4 length.It is taking undefined value in array.How to remove completely from array ? So that it length become 3.and out put become a,b,d

Pallavi Sharma
  • 635
  • 2
  • 14
  • 43

1 Answers1

2

Use JavaScript Array's built in splice method:

array.splice(index, 1);

The second parameter is the number of elements to remove, so 1 = "just this one".

Kong
  • 7,648
  • 14
  • 58
  • 89