如何从数组使用jQuery删除specifc值 [英] How to remove specifc value from array using jQuery
本文介绍了如何从数组使用jQuery删除specifc值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数组,看起来像这样:变种Y = [1,2,3];
I have an array that looks like this: var y = [1, 2, 3];
我想从数组中删除 2
是
。
我怎样才能把使用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]
<一个href=\"http://snipplr.com/view/14381/remove-item-from-array-with-jquery/\">http://snipplr.com/view/14381/remove-item-from-array-with-jquery/
这篇关于如何从数组使用jQuery删除specifc值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文