I want to add some metadata to an array, like a tag, but not actual data.
Say I have a symbol like:
const s = Symbol('foo')
Say I declare an array like so:
const v = [1,2,3];
is there a good way to tag the array with the symbol? Obviously adding it as a property might work:
v[s] = true;
I assume that this wont break anything and when the array is traversed the symbol property will never be hit? dunno!
Update: when I do this:
console.log(v);
I get:
[ 1, 2, 3, [Symbol(foo)]: true ]
but when I do:
v.forEach(x => console.log(x));
I just get:
1
2
3