English 中文(简体)
从联合材料系列物体移除元素
原标题:Removing element from JS array of objects
  • 时间:2011-11-17 01:25:59
  •  标签:
  • javascript

因此,我有这样的定义。

var myList = [];  

//I populate it like this
myList.push({ prop1: value1, 
                      prop2: value2,
                      prop3: value3
});

根据推进剂1值/通过阵列进行搜索,是否可以从名单上删除物品?

最佳回答

页: 1 你必须以某种方式控制阵列,检查每个物体在座的特性,并在你打上时进行拆除。

问题回答

Here you go:

myList = myList.filter( function ( obj ) {
    return obj.prop1 !== value;
});

<代码>数值/代码>为您重新测试的价值。

So, if the value of the prop1 property is equal to the value that you re testing against, obj.prop1 !== value will evaluate to false and that element will be filtered out.

这是否有助于:

Array.prototype.remove = function(s) {
  var i = this.indexOf(s);
  if(i != -1) this.splice(i, 1);
}

是否要求我的利比里亚人有综合类型的指数? 而是用钥匙 = 和 ;价值乳制品——即与推进剂1作为钥匙的价值相联系的阵列? 推进1的独特性如何? 如果不可能,则考虑执行多图。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签