gpt4 book ai didi

javascript - 如何按值搜索 javascript 对象?

转载 作者:行者123 更新时间:2023-11-28 18:33:56 25 4
gpt4 key购买 nike

我遇到了一种情况,必须在表格中显示以下响应。

[
{
"name": "Test",
"endPointURI": "http://10.10.10.1:123",
"successCount": 0,
"failureCount": 3761,
"successRate": 0.0,
"failureRate": 5.980012278871403,
"totalSent": 3761.0,
"totalSendRate": 5.980012307671908,
"latency": 0,
"oneMinuteSuccessRate": 0.0,
"fiveMinuteSuccessRate": 0.0,
"fifteenMinuteSuccessRate": 0.0,
"oneMinuteFailureRate": 9.971719382874516,
"fiveMinuteFailureRate": 23.609469948078925,
"fifteenMinuteFailureRate": 77.78484853747226,
"oneMinuteSendRate": 9.913005632492993,
"fiveMinuteSendRate": 23.60190467615165,
"fifteenMinuteSendRate": 77.7832824814743,
"lastSentSuccessTime": 0,
"sendRate": 5.980012307671908
},
[
{
"name": "Test2",
"endPointURI": "http://10.10.10.1:123",
"successCount": 0,
"failureCount": 3761,
"successRate": 0.0,
"failureRate": 5.980012278871403,
"totalSent": 3761.0,
"totalSendRate": 5.980012307671908,
"latency": 0,
"oneMinuteSuccessRate": 0.0,
"fiveMinuteSuccessRate": 0.0,
"fifteenMinuteSuccessRate": 0.0,
"oneMinuteFailureRate": 9.971719382874516,
"fiveMinuteFailureRate": 23.609469948078925,
"fifteenMinuteFailureRate": 77.78484853747226,
"oneMinuteSendRate": 9.913005632492993,
"fiveMinuteSendRate": 23.60190467615165,
"fifteenMinuteSendRate": 77.7832824814743,
"lastSentSuccessTime": 0,
"sendRate": 5.980012307671908
}]

我在这里将“名称”作为我的唯一 key 。

给定一个名称,我想返回具有“名称”的 JSON(或 javascript 对象)。

我在这里真的很困惑。有人可以帮忙吗?

最佳答案

如果您只想使用集合中具有特定 name 属性的对象,可以只调用 Array.prototype.find 方法吗?

let tableData = collection.find(function(myObject) {
return myObject.name === 'Test'
})

关于javascript - 如何按值搜索 javascript 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37470420/

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