【发布时间】:2020-06-13 02:36:54
【问题描述】:
我想在 javascript/typescript 中返回 JSON 对象,这些对象具有“团队”的真正布尔值。我使用的 JSON 示例是:
{
"state": "Texas",
"stateId": 1,
"team": true
},
{
"state": "California",
"stateId": 5,
"team": false
},
{
"state": "Rhode Island",
"stateId": 14,
"team": true
}
所以它应该以数组的形式返回 Texas 和 Rhode Island。到目前为止,我已经编写了以下代码,但它没有考虑不同的布尔值,我不确定为什么:
jsonString: any;
stateArray: any;
constructor() {
this.jsonString = JSON.stringify(data);
this.stateArray = JSON.parse(this.jsonString);
this.stateArray.filter(function(array) {
if (data["team"] === true) {
return array;
}
});
console.log(this.stateArray);
非常感谢您的帮助。
【问题讨论】:
标签: javascript arrays json typescript boolean