gpt4 book ai didi

javascript - 通过Json对象查询

转载 作者:行者123 更新时间:2023-11-30 10:15:07 25 4
gpt4 key购买 nike

这是我的 JSON:

[{"Id":1,"Order":1,"IsDone":true,"Text":"abc","Date":"6/14/2014"},
{"Id":2,"Order":2,"IsDone":false,"Text":"cde","Date":"6/15/2014"},
{"Id":3,"Order":3,"IsDone":false,"Text":"fgh","Date":"6/16/2014"}]

获取 IsDone == true 计数的最有效方法是什么?

最佳答案

您可以使用普通的 javascript 迭代:

var a=[{"Id":1,"Order":1,"IsDone":true,"Text":"abc","Date":"6/14/2014"},{"Id":2,"Order":2,"IsDone":false,"Text":"cde","Date":"6/15/2014"},{"Id":3,"Order":3,"IsDone":false,"Text":"fgh","Date":"6/16/2014"}]

var ct=0;
a.forEach(function(entry) {
if(entry.IsDone)ct++;
});
alert(ct);

关于javascript - 通过Json对象查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24300347/

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