[jQuery] 배열에서 특정 값만 제거하려고 할때

Posted by RAY.D
2015. 4. 28. 09:45 Web/javascript / jQuery
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.




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});​