我有以下数组。
"APP-A": {
"active": true
},
"APP-B": {
"active": true
},
"APP-C": {
"active": true
},
"BOOL-A": {
"active": true
},
"BOOL-B": {
"active": true
},
"BOOL-C": {
"active": true
},
我需要获取数组中 APP-* 的总数。 我正在尝试在 Angular JS 中实现。纯 JS 解决方案也会有所帮助。
TIA
最佳答案
一种方法是在对象的键上使用.filter()
:
var count = Object.keys(obj).filter(function (key) {
return key.indexOf(prefix) === 0;
}).length;
关于javascript - 计算 Javascript 数组索引的出现次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27393601/