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
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".
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.