Newbie: How to create a Javascript map?

Posted on
  • Code that works in my browser/Node.js uses "new Map()" but on my Pixl I'm getting:

    Uncaught ReferenceError: "Map" is not defined

    Is there a require("something") I need to call first?

  • Hi - I'm afraid there's no Map object built into Espruino.

    But what do you actually want to use it for? By default objects work basically the same way...

    a = {};
    a["foo"] = 42; // put
    console.log(a["foo"]); // get
    console.log("foo" in a); // check if inside
    delete a["foo"] // remove
    // ...
    
  • ! I hadn't considered using them like that, thanks!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Newbie: How to create a Javascript map?

Posted by Avatar for MarcEvan @MarcEvan

Actions