我有这个对象
ob = {
timePeriod: "Month",
device: ["A", "B"]
}
Run Code Online (Sandbox Code Playgroud)
当我使用
x=_.mapValues(ob, _.method('toLowerCase'))
Run Code Online (Sandbox Code Playgroud)
x 是
timePeriod: "month",
device: undefined
Run Code Online (Sandbox Code Playgroud)
它不能小写device数组.
数组没有toLowerCase函数.改为以下
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"]}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2933 次 |
| 最近记录: |