Is it possible to create a fixed length array in javascript?

后端 未结 9 1104
春和景丽
春和景丽 2020-12-03 00:59

Is it possible, in Javascript, to create an array whose length is guaranteed to remain the same?

For example, the array A is created with length 2. Subs

9条回答
  •  醉梦人生
    2020-12-03 01:43

    I've written a array-fixed https://github.com/MatrixAI/js-array-fixed which is a library providing you with fixed length arrays and fixed length dense arrays (arrays which always has its elements collapsed left or collapsed right).

    It supports many standard array operations such as splice and slice. But more operations can be added in the future.

    The concept of push doesn't make sense, instead there is caret* methods available that insert an element and push out elements that already exist into empty slots.

提交回复
热议问题