gpt4 book ai didi

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

转载 作者:数据小太阳 更新时间:2023-10-29 05:06:26 25 4
gpt4 key购买 nike

我有以下数组:

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 - 检查对象是否包含具有值的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8727857/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com