I have this object
ob = {
 timePeriod: "Month",
 device: ["A", "B"]
}
when i use
x=_.mapValues(ob, _.method('toLowerCase'))
x is 
 timePeriod: "month",
 device: undefined
it is not able to lowercase device array.
Array dont have toLowerCase function. Change to below
x = _.mapValues(ob, function(val) {
  if (typeof(val) === 'string') {
   return val.toLowerCase(); 
  }
  if (_.isArray(val)) {
    return _.map(val, _.method('toLowerCase'));
  }
});
JSON.stringify(x) // {"timePeriod":"month","device":["a","b"]}
                        var ob = {
    timePeriod: "Month",
    device: ["A", "B"]
}
var lowerCase = _.mapValues(ob, function(value){
    return _.isArray(value) ? _.map(value, _.toLowerCase) : _.toLowerCase(value);
})
                        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