I have an object like:
var obj = {
"01": ["a","b"],
"03": ["c","d"],
"04": ["e","c"]
};
and I know an array element ( say "c") of the object key's value then How to find first key value i.e "03" using lodash without using if else?
I tried like this using lodash and if else:
var rId = "";
_.forOwn(obj, function (array, id) {
if (_.indexOf(array, "c") >= 0) {
rId = id;
return false;
}
});
console.log(rId); // "03"
Expected Result: first key i.e "03" if element matches else "".
After seeing comments: Now I'm also curious to know about
Does I need to go with native javascript(hard to read program in the cases if we use more than 2 if blocks) or lodash way(easily readable program solution in one line)?