如何从JS中的数组中的不同对象获取特定字段的计数

时间:2015-04-18 10:57:55

标签: javascript

var Universities = [{
    "State": "ILLINOIS",
    "University": "North Park University",
    "Place": "Chicago"
}, {
    "State": "VERMONT",
    "University": "University of Vermont",
    "Place": "Berlington"
}, {
    "State": "FLORIDA",
    "University": "North Wood University",
    "Place": "Midland"
}, {
    "State": "NEW YORK",
    "University": "Pace State University(undergradations& post graduations",
    "Place": "NY"
}, {
    "State": "ILLINOIS",
    "University": "University of North Alabama",
    "Place": "Florence"
}, {
    "State": "ILLINOIS",
    "University": "Louisiana Technology University",
    "Place": "Ruston"
}, {
    "State": "North Carolina",
    "University": "East Carolina University",
    "Place": "Green Ville"
}, {
    "State": "ARKANSAS",
    "University": "Arkansas State University",
    "Place": "Jones boro"
}, {
    "State": "Oklahoma",
    "University": "University of Tulsa",
    "Place": "Tulsa"
}, {
    "State": "ILLINOIS",
    "University": "Rush University",
    "Place": "Chicago"
}]

UNIVERSITIES州有多少ILLINOIS? 请检查并帮助我。

1 个答案:

答案 0 :(得分:1)

如果我正确理解你的问题,也许使用filter可以弄清楚:

var result = Universities.filter(function (ele) {
    return ele.State == 'ILLINOIS';
});

console.log(result);