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

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?

4

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:

console.log(Reflect.ownKeys(jobsIds).length);

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) {
    console.log(key);
    console.log(jobIds[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.

2

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

console.log(Object.keys(jobIds).length);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.