3 ms·
var m = Object.create(null); Problem solved.
by joshuacc 11y ago
var m = Object.create(null);
Problem solved.
- chowells 11y agoThat solution doesn't cast javascript in a positive light. Why should you need to know that much about the guts of the language just to create an associative array that works properly?
- joshuacc 11y agoJavaScript objects aren't associative arrays. They inherit property values from their prototype. Not just __proto__, but hasOwnProperty, etc. If you want to abuse objects in this way, it makes sense that you need a special approach to opt out of inheritance. A better approach is to just use Map. var m = new Map();
- amelius 11y agoIt would have been so much better if inheritance was opt-in rather than opt-out.