javascript – 检查对象是否包含具有值的属性

前端之家收集整理的这篇文章主要介绍了javascript – 检查对象是否包含具有值的属性前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有以下数组:
SoftwareBadges =
[
    { Title: "Playtech",Guid: "7e9",xPos: "96" },{ Title: "BetSoft",Guid: "890",xPos: "169" },{ Title: "WagerWorks",Guid: "35c",xPos: "242" },{ Title: "Rival",Guid: "c35",xPos: "314" },{ Title: "NetEnt",Guid: "59e",xPos: "387" },{ Title: "MicroGaming",Guid: "19a",xPos: "460" },{ Title: "Cayetano",Guid: "155",xPos: "533" },{ Title: "OpenBet",Guid: "cfe",xPos: "607" },{ Title: "RTG",Guid: "4e6",xPos: "680" },{ Title: "Cryptologic",Guid: "05d",xPos: "753" },{ Title: "CTXM",Guid: "51d",xPos: "827" },{ Title: "Sheriff",Guid: "63e",xPos: "898" },{ Title: "Vegas Tech",Guid: "a50",xPos: "975" },{ Title: "Top Game",Guid: "0d0",xPos: "1048" },{ Title: "Party Gaming",Guid: "46d",xPos: "1121" }
]

现在,我需要检查它们是否包含值,并返回对象,例如:

var test = "7e9" // Guid

我如何获得包含此Guid值的对象?
在示例中,它应该返回PlayTech对象.

在C#中使用linq我可以做类似的事情:
var x = SoftwareBadges.Where(c => c.Guid == test)

我怎么能用javascript做到这一点?

解决方法

作为关联数组,您可以尝试这样做:
for (var s in SoftwareBadges) {
    if (SoftwareBadges[s]["Guid"] == "7e9")
       alert(SoftwareBadges[s]["Title"]);
}

猜你在找的JavaScript相关文章