数组对象转字符串, [{name: '张', age: 5 }, { name: '李', age: 4 } , { name: '王', age: 3 }] 变为张-5,李-4,王-3。用逗号拼接?
数组对象转字符串, [{name: '张', age: 5 }, { name: '李', age: 4 } , { name: '王', age: 3 }] 变为张-5,李-4,王-3。用横杠和逗号拼接?
回答:
[ { name: "张", age: 5 },
{ name: "李", age: 4 },
{ name: "王", age: 3 },
]
.map(({ name, age }) => `${name}-${age}`)
.join(",");
回答:
(arr.map(item=>item.name + '-' + item.age)).join(',')
回答:
arr.map(({name, age}) => `${name}-${age}`).join()
以上是 数组对象转字符串, [{name: '张', age: 5 }, { name: '李', age: 4 } , { name: '王', age: 3 }] 变为张-5,李-4,王-3。用逗号拼接? 的全部内容, 来源链接: utcz.com/p/934779.html