0

Questions:

  1. Does ECMA 5 supports Map & Set & List collections?
  2. Preferred approach to define and iterate Map and Set in Aura? - I think we have to use objects for Maps like:

<aura:attribute name="myMap" type="map" default="{}"/>

            var mapFirst = {};
            mapFirst[0] = 'Hello1';
            mapFirst[1] = 'Hello2';
           
            alert(JSON.stringify(mapFirst));

        

        let mapThird = response.getReturnValue(); //map is returned
        let mapFourth = {};
        for(let key in mapThird){
             mapFourth[key] = mapThird[key];       
         }

but how to use create a set and use in java script?

  1. Why Aura javascript support Map and Set function like has, get, set, add etc?

Please I need a clear difference between ECMA5 and 6 collections usage in Aura. Not able to clear understand the collections usage in aura.

1
  • 1
    is there any reason why you are still using aura, instead of LWC ?
    – glls
    Jun 18, 2021 at 19:06

1 Answer 1

2

Does ECMA 5 supports Map & Set & List collections?

No.

Preferred approach to define and iterate Map and Set in Aura? - I think we have to use objects for Maps like:

Because of how Aura handles serialization and deserialization of objects, you should prefer to use Map instead of Object for attribute types. You can, however, use the Map object internally in your JavaScript, as long as your browser supports it.

but how to use create a set and use in java script?

You construct them as normal:

let myMap = new Map();
let mySet = new Set();

Check out the MDN documentation on how to use Map and Set, including constructors and special rules for their use.

Why Aura javascript support Map and Set function like has, get, set, add etc?

Because of how the compiler works, you're technically allowed to use any script supported by the browser, even the latest in ECMA features, but Aura only formally promises ECMA 5 and ECMA 6 Promises (and nothing newer). It is recommended that you strictly keep to ECMA 5 and Promises in Aura, and use LWC if you want to support newer features.

Please I need a clear difference between ECMA5 and 6 collections usage in Aura. Not able to clear understand the collections usage in aura.

ECMA 5 collections are officially supported, ECMA 6 collections are supported only if the browser supports them. Of course, this should only be a problem if you still need to support IE 11, which nobody should be using these days (but some people still are...).

To be crystal clear, you should not attempt to use Map or Set in Aura JavaScript, and you should always use List and Map as Aura attribute types instead of Set, Object, or Array. It's just one of the many quirks of Aura, which is why it's also recommended you use LWC whenever possible.

2
  • let myMap = new Map(); and let mySet = new Set(); are ECMA 6 collections. So I shouldn't be using in Aura Js instead use Map Objects to create a temporary map (if I dont want to store as an attribute). Question 2: Can I create temporary JS set in aura without defining at attribute of view markup. Question 3: Is defining set at the attribute level, then fetching it in JS will help me to behave a variable as a Set right?
    – Sukruti
    Jun 18, 2021 at 19:47
  • @RajaRay (1) If you use Map/Set in Aura, it won't work in IE 11, but you can technically use it if browser support is present. (2) Yes, you can use any supported data type in controller/helper. (3) No, you shouldn't use Set as an attribute.
    – sfdcfox
    Jun 18, 2021 at 20:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .