FixedArray
npm install fixed-length-array --save
Usage
FixedArray
inherits native Array
class and all its methods.
2 // [ , ]1 2 // [ 1, 2 ] — yep, as native ArrayFixedArray // [ 1, 2 ] { 1 2}FixedArray // [ 1 , 2 ]
Methods push()
and unshift()
works different. If you create an array with fixed length it keeps his length, so methods push()
and unshift()
will remove elements from other end of array (shift()
and pop()
respectively). Methods pop()
and shift()
is not accesible manually.
const array = FixedArrayconsole // 2arrayconsole // 2 — length not changedconsole // [ 2, 3 ] arrayconsole // still 2console // [ 1, 2 ]
As you can see FixedArray
is not resizable. Only way to resize is create new FixedArray
.