Associate Array Splice Does Not Work
I am trying to understand why in nodejs array splice does not work on an associate array. var a = []; a['x1'] = 234234; a['x2'] = 565464; console.log('Init-------'); showIt();
Solution 1:
In JavaScript there is no such thing as an associative array -- there are arrays (like normal arrays in other languages) and objects (like assoc. arrays in other languages). In your example a
is a normal array but you set non-numerical keys on it, so the normal array methods (like splice) do not see it. They only look in the range 0...a.length
.
Making a
an object won't help; it is not possible to splice an object. Try using only numerical keys ([1]
instead of ['x1']
).
Post a Comment for "Associate Array Splice Does Not Work"