我有一个包含 100 个索引的数组
const randomArr = [...Array(100).keys()]
如何像这样返回 100 个数组
[{index: i}, {title: `title${i}`}]
其中i
应该是随机数组的索引。
最佳答案
使用Array.from()
:
const result = Array.from({ length: 100 }, (_, i) => [
{ index: i }, { title: `title${i}` }
]);
console.log(result);
关于javascript - 减少 JavaScript 中的对象数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49432391/