# HashMap nodejs p5js

**URL:** https://discourse.processing.org/t/hashmap-nodejs-p5js/1381
**Category:** Beginners
**Created:** [June 30, 2018, 11:10am UTC](https://discourse.processing.org/t/hashmap-nodejs-p5js/1381 "2018-06-30T11:10:43Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![lmccandless](https://avatars.discourse-cdn.com/v4/letter/l/f0a364/32.png) [@lmccandless](https://discourse.processing.org/u/lmccandless)
#### Post date: [June 30, 2018, 11:10am UTC](https://discourse.processing.org/t/hashmap-nodejs-p5js/1381/1 "2018-06-30T11:10:43Z")

</div>

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

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [June 30, 2018, 2:11pm UTC](https://discourse.processing.org/t/hashmap-nodejs-p5js/1381/2 "2018-06-30T14:11:47Z")

</div>

> [@lmccandless](#):
>
> Never mind. I guess every Array is a HashMap.

Actually, every JS Object functions kinda like a HashMap. 🤓

> [@lmccandless](#):
>
> How can I get the size of an Array when it has String keys?

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

> **[Array: length - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)**
>
> The length data property of an Array instance represents the number of elements in that array. The value is an unsigned, 32-bit integer that is always numerically greater than the highest index in the array.

An invalid index becomes a regular keyed property which is invisible to its _length_ property. 👻

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

> **[Map - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)**
>
> The Map object holds key-value pairs and remembers the original insertion order of the keys.
> Any value (both objects and primitive values) may be used as either a key or a value.

> **[Keyed collections - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Keyed_collections)**
>
> This chapter introduces collections of data which are indexed by a key; Map and Set objects contain elements which are iterable in the order of insertion.
