【发布时间】:2020-06-20 09:40:36
【问题描述】:
我的代码可以运行,但运行起来似乎异常缓慢。
我有一组要搜索的值,我有一个要过滤的 JSON。
var JSONPull;
var FilterJSON = [];
var TypeIDs = [34,35,36,37,38,39,40,11399,1230,17470,17471,1228,17463,17464,1224,17459,17460,18,17455,17456,1227,17867,17868,20,17452,17453,1226,17448,17449,21,17440,17441,1231,17444,17445,1229,17865,17866,1232,17436,17437,19,17466,17467,1225,17432,17433,1223,17428,17429,22,17425,17426,11396,17869,17870];
fetch('URL API')
.then(res => res.json())
.then((out) => {
JSONPull = out;
TypeIDs.forEach(function (index){
FilterJSON = JSONPull.filter((element) => {
console.log("index: "+index);
console.log(element);
console.log("type_id: "+ element.type_id);
element.type_id === index;
});
})
})
console.logs 更多的是在测试时观看代码,但绝对不应该导致这些性能问题。
您能告诉我有关性能优化的建议吗?
【问题讨论】:
-
我觉得这个问题应该发到codereview.stackexchange.com
-
啊,不知道那是一回事……谢谢
标签: javascript json performance filtering