使用lodash,我需要将一个对象数组转换为字符串数组。
原始数组,
我尝试了这种方法,
原始数组,
const tags = [{
"display": "tag1",
"value": "tag1"
}, {
"display": "tag2",
"value": "tag2"
}]
预期结果:
const tags = ["tag1", "tag2"]
我尝试了这种方法,
const data = [{
"display": "tag1",
"value": "tag1"
}, {
"display": "tag2",
"value": "tag2"
}]
const result = _(data)
.flatMap(_.values)
.map((item) => { if (typeof item === 'string') { return item; } else { return; } })
.value()
console.log('result', result);