如何使用jQuery从数组中删除特定值 [英] How to remove specific value from array using jQuery
本文介绍了如何使用jQuery从数组中删除特定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个看起来像这样的数组:var y = [1, 2, 3];
I have an array that looks like this: var y = [1, 2, 3];
我想从数组 y
中删除 2
.
I would like to remove 2
from array y
.
如何使用 jQuery 从数组中删除特定值?我试过 pop()
但它总是删除最后一个元素.
How can I remove a particular value from an array using jQuery? I have tried pop()
but that always removes the last element.
推荐答案
一个有效的 JSFIDDLE
你可以这样做:
var y = [1, 2, 2, 3, 2]
var removeItem = 2;
y = jQuery.grep(y, function(value) {
return value != removeItem;
});
结果:
[1, 3]
http://snipplr.com/view/14381/remove-item-from-array-with-jquery/
这篇关于如何使用jQuery从数组中删除特定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文