RangeError Invalid array length Array size is not a small enough positive integer javascript fixed

preview_player
Показать описание
Dear friends, please visit
for detailed explanation with text and source code

In this small video i am discussing about two types of errors as listed below
1.RangeError: Invalid array length.
2.RangeError: Array size is not a small enough positive integer.

Using examples, I explain what is the reason of Invalid array length and Array size is not a small enough positive integer and How to avoid this type of RangeError

By watching this video you will understand
What are the different types of methods to declare an array in javascript

1.Using array constructor Array() with or without we can create new instance of an array
2.Using array literal notation

So by watching you will understand that when you assign a value to length property of the array it should not be

1.Should not be a Negative number
2.Should not be a floating-point number
3.Should not be a value greater that 2^32-1

// Maximum allowable length of Array is 2^32-1

//Let us check examples to use Array() constructor to create Array objects.
//Array() can be used with or without new keyword. in both cases .it creates a new instance of array

let arr1 = new Array(10000000000000000000000000000000000000000000000000000000000000000000000000000000)
let arr3= [];

// assign length of an array with negative value

// assign length of an array with floating point value

ERROR OUTPUT ON TERMINAL

^

RangeError: Invalid array length
at Module._compile (node:internal/modules/cjs/loader:1226:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1280:10)
at Module._load (node:internal/modules/cjs/loader:930:12)
at node:internal/main/run_main_module:23:47

Рекомендации по теме