In the process of creating a form to interact with a remote API, I aim to construct a GET request query string depending on which checkboxes the user chooses.
Initially, I considered using a series of if/else statements to check whether the model object key is set to true or false, and then compile a clean array containing only the names of the object keys. However, I question if there is a more automated approach available?
One idea is to utilize angular.foreach, but I am uncertain about how to extract the object key names as values.
For instance:
function submit() {
var pushData = [];
angular.foreach(vm.export, function(item, index){
if (item === true) {
pushData.push(index);
}
})
}
Here is the object from which the data is being retrieved:
vm.export = {
'servers': true,
'apps': false,
'users': true,
'userID': 1234
}
How can I add the key names with TRUE values to the pushData array?