我有一个json对象,其格式如下
"data": [{
"firstName": "XYZ",
"lastName": "Admin",
"userId": 1,
"companyLogo":"Logo"
}, {
"firstName": "ABC",
"lastName": "Admin",
"userId": 1,
"companyLogo":"Logo1"
}, {
"firstName": "EFG",
"lastName": "Admin",
"userId": 1,
"companyLogo":"Logo2"
}]
我希望以下输出使用nodejs
中的lodash将徽标名称与其路径连接起来 "data": [{
"firstName": "XYZ",
"lastName": "Admin",
"userId": 1,
"companyLogo":"E:/Logo"
}, {
"firstName": "ABC",
"lastName": "Admin",
"userId": 1,
"companyLogo":"E:/Logo1"
}, {
"firstName": "EFG",
"lastName": "Admin",
"userId": 1,
"companyLogo":"E:/Logo2"
}]
是否存在支持此类连接的任何函数?
答案 0 :(得分:1)
不需要外部库:
var data = [
{
"firstName": "XYZ",
"lastName": "Admin",
"userId": 1,
"companyLogo":"Logo"
},
{
"firstName": "ABC",
"lastName": "Admin",
"userId": 1,
"companyLogo":"Logo1"
},
{
"firstName": "EFG",
"lastName": "Admin",
"userId": 1,
"companyLogo":"Logo2"
}
]
var new_data = data.map(function(elem){ elem.companyLogo = "E: /" + elem.companyLogo; return elem });
console.log(new_data);