I have the following script:
JavaScript
x
11
11
1
for (var i = 0; i < obj.length; i++) {
2
obj.push("It's nice to work at Bass Pro Shop!");
3
}
4
5
return obj;
6
}
7
8
function validate(reason) {
9
return reason.split(' ').length < 3
10
}
11
I’m receiving this error when trying to run my JS:
FATAL ERROR: invalid array length Allocation failed – JavaScript heap out of memory
I’ve checked other similar posts that say to increase the memory size f.x., node --max-old-space-size=16000 yourFile.js
or from FATAL ERROR to my script they both don’t work. Any help would be greatly appreciated.
Advertisement
Answer
Took me a while to write your code down. You shouldn’t be posting images of code.
Anyway, the problem lies here:
JavaScript
1
5
1
for(var i = 0; i < obj.length; i++)
2
{
3
obj.push("It's nice to work at Devoteam!");
4
}
5
You are looping the same array to where you push more data inside the loop, thus the loop will never end and the array size becomes too large.