I was tweaking with js, and I was wondering if there is a way to add another element in an array that is being mapped inside one of the map iterations, to then make that vale be processed by the map.
Example:
const array1 = [1, 4, 9, 16];
// Pass a function to map
var oneIter = true;
const map1 = array1.map((x) => {
if (oneIter) {
oneIter = false;
array1.push(10);
}
return x * 2
});
console.log(array1);
console.log(map1);
// Expected output: Array [2, 8, 18, 32, 100], Actual output: Array [2, 8, 18, 32]
Thank you for your time.
Tried to add an element by simply pushing it during a js map iteration.