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

Time:12-28

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

CodePudding user response:

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

CodePudding user response:

arr2.length starts with 10

Every time you call push you add one element and increase arr2.length

When arr2.length reaches 144998948 the process throws an error

  • Related