I have these 2 types of looping an array. https://codesandbox.io/s/confident-rubin-e4ms1?file=/src/App.js
export default function App() {
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const useFor = () => {
const res = [];
for (let i = 0; i < arr.length; i++) {
res.push(
<span className="indent" key={i}>
{arr[i]}
<br />
</span>
);
}
return res;
};
return (
<div className="App">
{arr.map((i) => (
<span key={i}>
{i}
<br />
</span>
))}
<hr />
{useFor()}
</div>
);
}
Which is the fastes way to loop an array in ReactJs: for(){}
or map()
?