So I am trying to accomplish turning an array of booleans to an array of strings, (only of the booleans that were set to true). This can be in either javascript, or underscore. Let me show you what I mean.
I have an array like this :
[{"item1" : [{"one": true, "two": false}]}, {"item2" : [{"one": false, "two": true}]}];
And the end result I am looking for is :
[{"item1" : ["one"]}, {"item2" : ["two"]}];
It's worth mentioning, all of these keys will be dynamic. I can't seem to figuire out how I should traverse this array to complete this task. The simpler, the better! Thanks!
Here's my poor attempt :
$scope.testObject = _.map($scope.filterArray, function(obj) {
_.map(obj.values, function(value) {
if (value === true) {
return value;
}
});
});
(this does not work). What I am trying to accomplish is turning the values of these objects ([{"one":true, "two": false}] for example) into an array of strings, the strings being the keys of the items that are set to true.
So for example
[{"one":true, "two": false}]
would turn into
["one"]
Because two is false.