Initially, I set out to create a function that would determine whether my data object contained a truthy value and return a boolean accordingly.
The specific key or value that is truthy is not important to me; all that matters is the presence of a truthy value within the data.
var fruits = { apples: false, oranges: true, bananas: true }
Upon iterating over this object, the expected return should be true
as there are indeed true
values present.
While the following function successfully achieved the desired outcome:
return Object.values(fruits).some(function(k) {
return k;
});
I faced compatibility issues with IE which prevented me from using Object.value
or array.some
.
A suggested Polyfill recommended using .map
in order to access each value individually. However, eliminating .some()
proved to be a challenge. I experimented with .filter()
, but it led me back to square one where it returned the truthy key
instead of just verifying the presence of any truthy value in the dataset.