如何将以下对象数组转换为 javascript 字符串:"contacts": [{"contactName": "ABC XYZ", "contactDesgn": "Associate Director", "contactPhone": "9892265172", "contactEmail": "ABC.XYZ@test.com", "level": "L4"}]我希望得到的字符串是这样的:<#>ABC XYZ<#>Associate Director<#>9892265172<#>ABC.XYZ@test.com<#>L4<$>
2 回答
交互式爱情
TA贡献1712条经验 获得超3个赞
let contact = [{"contactName": "ABC XYZ", "contactDesgn": "Associate Director", "contactPhone": "9892265172", "contactEmail": "ABC.XYZ@test.com", "level": "L4"}];
let result = contact[0];
let string = `<#>${result.contactName}<#>${result.conatactDesign}<#>${result.contactPhone}<#>${result.contactEmail}<#>${result.level}<$>`
饮歌长啸
TA贡献1951条经验 获得超3个赞
用于Object.values()从 JSON 中获取一组值。用于Array.join通过<#>并最终连接前导标签和尾随标签来链接值。
contacts = [{"contactName": "ABC XYZ", "contactDesgn": "Associate Director", "contactPhone": "9892265172", "contactEmail": "ABC.XYZ@test.com", "level": "L4"}];
console.log ('<#>' + Object.values (contacts[0]).join ('<#>') + '<$>');
添加回答
举报
0/150
提交
取消