I had the need for some simplicity, to work with methods like push
, pop
, shift
, unshift
from Array
s prototype, that do not change itself.
The basic concept would look like something like this. I just implemented some basic methods to illustrate my thoughts. However, there are more possibilities. Read the note below.
array = array.slice(0, -1);
array = array.slice(1);
array = array.concat(1337);
array = [0].concat(array);
I have wrapped/aliased these methods in some simple functions (see index.js below):
var array = [1, 2, 3];
array = push(array, 4); // => [1, 2, 3, 4]
array = pop(array); // => [1, 2, 3]
array = unshift(array, 0); // => [0, 1, 2, 3]
array = shift(array); // => [1, 2, 3]
Whoops, nothing here!
Why that?
...talking about the possiblities about protected array manipulation, really?!