0

I'm using Map in NodeJS 0.10.36 by enabling harmony flag. I'm able to create a map, set and get data, but other methods like size, keys(), entries(), forEach yield undefined results.

var k = new Map();
k.set('a', 1);
k.set('b', 2);

console.log('Printing out b', k.get('b')); //prints 2

var length = k.size;
console.log('Size of my map', length); // prints undefined

for(var key in k.keys()) {
    console.log('keys value',key);
} // undefined

Is there something that I could do to make it work?

1 Answer 1

3

You have an old Node version. My Node (0.12.4) prints 2 for k.size. k.keys() should be iterated with of, not with in:

for(var key of k.keys()) {
    console.log('keys value',key);
}

tl;dr: Upgrade Node.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.