How to use an array to tabulate a set of values in JavaScript

1 Answer

0 votes
const arr = [];

for (let i = 0; i < 10; i++) {
    arr.push([2 ** i, 2 * i ** 2]);
}

console.table(arr);



/*
run:

┌─────────┬─────┬─────┐
│ (index) │  0  │  1  │
├─────────┼─────┼─────┤
│    0    │  1  │  0  │
│    1    │  2  │  2  │
│    2    │  4  │  8  │
│    3    │  8  │ 18  │
│    4    │ 16  │ 32  │
│    5    │ 32  │ 50  │
│    6    │ 64  │ 72  │
│    7    │ 128 │ 98  │
│    8    │ 256 │ 128 │
│    9    │ 512 │ 162 │
└─────────┴─────┴─────┘

*/

 



answered May 3, 2024 by avibootz
...