Supplied with:
let input = [0, 1, 2,,,,,7]
I am aiming for:
let output = [, 1, 22, 333, 4444, 55555, 666666, 7777777]
(meaning each value is equal to the key times the key)
How can I perform a map
operation (or similar) on the input even if it contains empty values?
When using input.map()
, the resulting array will be [, 1, 22,,,,,7777777]
since map
naturally skips over empty entries. The data could vary from strings, objects, numbers, etc., but for simplicity, numbers are used in this example.