I am working on a task where I need to fetch data from an API and store only the values that are marked as "true" in a variable. The API response is listed below:
API Output Data
{
"BNG-JAY-137-003": false,
"BNG-JAY-137-004": true,
"BNG-JAY-137-005": false
}
Shown below is the function I am using. It aims to filter out and save the data with a value of true into a separate array. In this code snippet, selected_data
represents the API data.
on(){
for(let key in this.selected_data) {
if(this.selected_data[key]) {
// At this point, I want to collect the true values into an array.
}
}
}