Web/javascript / jQuery
[jQuery] 배열에서 특정 값만 제거하려고 할때
RAY.D
2015. 4. 28. 09:45
How to remove specific value from array using jQuery
배열에서 특정 값만 제거하려고 할때
You can do something like this:
var y = [1, 2, 3]
var removeItem = 2;
y = jQuery.grep(y, function(value) {
return value != removeItem;
});
Result:
[1, 3]
또다른 방법
1 | $(document).ready( function (){ |
2 | var arr = [ "jQuery" , "JavaScript" , "HTML" , "Ajax" , "Css" ]; |
3 | var itemtoRemove = "HTML" ; |
4 | arr.splice($.inArray(itemtoRemove, arr),1); |
5 | }); |