HashMap nodejs p5js

I’m coming from processing to p5js and looking for HashMap functionality.

I’m using node.js and did npm install hashmap

in my test sketch, doing var hm = new HashMap(); inside setup() prevents my sketch from working. Not sure how to go about debugging this as I’m very new to javascript, doing npm list shows hashmap is installed.

nevermind, I guess every array is a hashmap.

how can I get the size of an array when it has string keys? .length doesn’t work. I read to use jquery to get .size() for arrays, i did npm install jquery but get “TypeError: spriteAtlas.size is not a function”

found solution, Object.keys(spriteAtlas).length

Actually, every JS Object functions kinda like a HashMap. :nerd_face:

An Array’s length property only tracks down the quantity of positive integer indices up to 2**32: :face_with_monocle:

An invalid index becomes a regular keyed property which is invisible to its length property. :ghost:

Rather than forcing an Array or an Object to behave like a Java Map, go w/ an actual JS Map container: :star_struck:

1 Like