I am trying to do something in pure JS. I have an Object like so
var data = {
"Something": true,
"Something else": false,
"Blah": false,
"a fish ISA": true
};
What I want to do is filter anything which has true to its own Object. At the moment I am trying
var thingFunctions = Object.keys(data).filter(function(e) {
return typeof data[e] == 'function'
});
But I think this is incorrect. How can I get the data with a value of true to its own Object?
Thanks
So firstly you have no functions inside data, so doing a check on functions will return nothing.
var data = {
"Something": true,
"Something else": false,
"Blah": false,
"a fish ISA": true
};
var thingFunctions = Object.keys( data ).filter(function( e ) {
return data[ e ] === true;
});
console.log( thingFunctions );
// Will result in [ 'Something', 'a fish ISA' ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With