如何在 Javascript 中将数组转换为对象数组[重复]

2024-02-29

我想转换一个数组,如:

[ 'John', 'Jane' ]

放入对象对数组中,如下所示:

 [{'name': 'John'}, {'name':'Jane'}]

请帮助我这样做..


尝试数组中的“map”函数:

const output = [ 'John', 'Jane' ].map(name => ({name}));
console.log(output);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 Javascript 中将数组转换为对象数组[重复] 的相关文章

随机推荐