Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

push() to array made with constructor results in Fatal Error (works fine with literal array)

This code gives me a weird error. Does anyone has an idea what went wrong?

I can push items, but not in the for loop.
Works fine with array made with Literal Syntax = []
Also works fine when filling with arr2[i] = 5 instead of .push() method

const arr2 = Array(10);

for(let i = 0; i < arr2.length ; i++)
{
    arr2.push(5)
}

#
# Fatal error in , line 0
# Fatal JavaScript invalid size error 144998948
#
#
#
#FailureMessage Object: 00000009F4FFE470
 1: 00007FF6F1291B7F node_api_throw_syntax_error+203775
 2: 00007FF6F11A2B2F v8::CTypeInfoBuilder<void>::Build+11951
 3: 00007FF6F2012CF2 V8_Fatal+162
 4: 00007FF6F1B54A55 v8::internal::FactoryBase<v8::internal::Factory>::NewFixedArray+101
 5: 00007FF6F19D9D43 v8::internal::FeedbackNexus::ic_state+64883
 6: 00007FF6F19F8650 v8::debug::Script::GetIsolate+14064
 7: 00007FF6F18453B0 v8::internal::CompilationCache::IsEnabledScriptAndEval+25952
 8: 00007FF6F1D51E81 v8::internal::SetupIsolateDelegate::SetupHeap+558193
 9: 00007FF671E8EC86

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You are pushing into the same list you are iterating with a codition "i < arr2.length"
that means this will run forever and will grow to infinite

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading