I have an array of 100 indices
const randomArr = [...Array(100).keys()]
How to return 100 array like this
[{index: i}, {title: `title${i}`}]
where i should be index of random array.
I have an array of 100 indices
const randomArr = [...Array(100).keys()]
How to return 100 array like this
[{index: i}, {title: `title${i}`}]
where i should be index of random array.
Use Array.from():
const result = Array.from({ length: 100 }, (_, i) => [
{ index: i }, { title: `title${i}` }
]);
console.log(result);
I think you mean that you want a list like
[{index: i, title: `title${i}`}]
But here goes anyway.
Using Array.prototype.fill
const randomArr = Array(100).fill(0).map((e, i) =>
[{ index: i}, {title: `title${i}`}]
);
console.log(randomArr);