const m =mmmmm 1m 2m 3m 4
elements are treated by identity, like
Construct an array-keyed map object:
const arrayKeyedMap = require('array-keyed-map') const akmap = arrayKeyedMap()
The constructor takes no arguments.
value: any value
Sets the value for the given array.
Objects in the array are treated by identity. The identity of the array object itself is irrelevant.
Returns the previously assigned value for this array, or
Deletes the value at this exact array. Does not affect other array, even if they are prefixes or extensions of this one. Remember to do this if you no longer need a array: the keys and values are not automatically garbage-collected, even if the objects used as keys go out of scope!
Why is this better than
.join('/')ing the keys and using a regular object?
Because your array elements might have
/s in them. For example, the array
['a', 'b']would both resolve to the array
So use something other than a
/? Sure, but then you have the same problem with elements possibly containing that.
So use a sufficiently long unguessable string like
03f2a8291a700b95904190583dba17c4ae1bf3bdfc2834391d60985ac6724940? That that wastes RAM/disk when you have many long arrays.
Because even an empty
Objecthas properties on it (e.g.
length) which your stored keys might accidentally overwrite, causing subtle bugs.
Because you might want your array to contain objects rather than strings, and objects are inefficient to stringify, frequently even impossible.
What version of JS does this rely on?
Does this implement the full
No. See related issue. I'd take a PR though! 🌠