Why am i seeing 'uncaught rangeerror: invalid array length' in javascript?

This error is usually encountered when trying to create an array of an invalid length.

Example:


let arr = new Array(-1);

Solution:


let arr = new Array(10);
Ensure that you provide a valid positive integer when setting an array's length.

Beginner's Guide to JavaScript