component.set("v.filePushJobIds", actionResult.getReturnValue());
        var jobsIds = component.get("v.filePushJobIds");

I see that my map prints out fine on its own ie.

{707g0000028jBClAAM: "069g0000001QJk9AAG", 707g0000028jBCmAAM: "069g0000001QJjcAAG", 707g0000028jBCnAAM: "069g0000001QJofAAG", 707g0000028jBCoAAM: "069g0000001QJjbAAG", 707g0000028jBGcAAM: "069g0000001QJlXAAW", …}

but for some reason i cannot get the size of this map. I've looked up how to do this in JS and SF and have tried size, length, size(), i've tried iterating through the map and no luck. Either returns undefined or errors out. Any ideas?


2 Answers 2


Based on what you pasted your map is represented as a single object with named attributes.

This object in JS has no implementation of .size so it wont show you the size.

You could try something like:


Reflect.ownKeys(object) should convert your object into an array allowing length and other array functions such as forEach to work. Then you would do something like:

let keys = Reflect.ownKeys(jobIds);

keys.forEach(function(key) {
    // ... do more stuff
}, this);

Keep in mind that keys only contains the attribute names, you will have to do object[keys[0]] or something like above to be able to get to the values.


You can check the length of the keys the object owns:

  • Hi @sfdcfox , How to check whether object has a key or not ? Commented Feb 18, 2020 at 18:40
  • @amidstCloud if(key in varName) gives you true if it has a given property anywhere in its prototype chain, while if(varName.hasOwnProperty(key)) will tell you if that property directly exists on an object without checking the prototype chain.
    – sfdcfox
    Commented Feb 18, 2020 at 19:13
  • thanks a lot.. I am returning the a map<Id,Integer> from Apex class and storing it in a var in the component controller. I was looking for a way to check size/length of it , but both are coming as undefined Commented Feb 18, 2020 at 19:21

You must log in to answer this question.

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