I am working on returning JSON objects in JavaScript/TypeScript that have a true boolean value for the "team" property. For example, the JSON data I am using is as follows:
{
"state": "Texas",
"stateId": 1,
"team": true
},
{
"state": "California",
"stateId": 5,
"team": false
},
{
"state": "Rhode Island",
"stateId": 14,
"team": true
}
My goal is to create an array containing only Texas and Rhode Island. However, my current code does not properly filter based on the boolean value of "team". Here is the snippet:
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);
Any assistance or insights on where I might be going wrong would be greatly appreciated. Thank you!