admin管理员组文章数量:1332395
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.
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.
2 Answers
Reset to default 5Array 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);
})
本文标签: javascriptuse lodash to lowercase internal array elementStack Overflow
版权声明:本文标题:javascript - use lodash to lowercase internal array element - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742281813a2446232.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论