标签云

微信群

扫码加入我们

WeChat QR Code

从一个JavaScript数组中删除对象?[重复]

Possible Duplicate:
Remove specific element from a javascript array?

Specifically I have an array as follows:

var arr = [
    {url: 'link 1'},
    {url: 'link 2'},
    {url: 'link 3'}
];

Now you want to remove valuable element url "link 2" and after removing the only arrays as follows:

arr = [
    {url: 'link 1'},
    {url: 'link 3'}
];

So who can help me this problem? Thanks a lot


I do not think this is a a direct duplicate of that question. In the other question only a primitive value is used. indexOf will not work here. So, unless the index is (always) known, a bit of the puzzle is missing with splice...

2018年05月27日25分50秒

I have seen this question many times already.

2018年05月27日25分50秒

arr.filter(function(element){ return(element.url === 'link 2'? false :true); })

2018年05月27日25分50秒

Please include the requirements... not everyone is so lucky to have such function (without a shim).

2018年05月27日25分50秒

pst Yep, Added.

2018年05月27日25分50秒

Perfect, helped me allot!

2018年05月27日25分50秒