【发布时间】:2017-08-03 04:11:25
【问题描述】:
我有一个类似的数组:
var arr = ["hello","world"]
// This array can contain any number of strings
像这样的对象:
var obj_arr = {
"abc-hello-1": 20,
"def-world-2": 30,
"lmn-lo-3": 4
}
我想要一个只包含那些键的对象,它包含上述数组值作为子字符串。 例如:
结果将如下所示:
var result = {
"abc-hello-1": 20,
"def-world-2": 30,
}
我想做这样的事情(使用 lodash):
var to_be_ensembled = _.pickBy(timestampObj, function(value, key) {
return _.includes(key, "hello");
// here instead of "hello" array should be there
});
【问题讨论】:
标签: javascript json object lodash