2

I generated a list earlier on in the code and stored it.

<aura:attribute name="voiceContactList" type="List"/>
contactList: Proxy
    [[Handler]]: Object
        [[Target]]: Array(1)
            0: {firstName: 'Ktest2', firstName2: 'Ktest3', LastName: 'Test2', LastName2: 'Test3', streetAddress: '911 SomeTrail Trail', …}
            length: 1 [[Prototype]]: Array(0) [[IsRevoked]]: false

The list is there in contactList but I haven't been able to access this list.

console.log('contact = '+ contactList);

Just shows it as [object,object]

1
  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Mar 11, 2022 at 17:46

2 Answers 2

1

The strange syntax you see is because the Lightning LockerService has wrapped your object in a Proxy. This makes it inaccessible to anything other than your own javascript context.

To access in the console, you can JSON stringify:

console.log('contact = '+ JSON.stringify(component.get("v.contactList"))); 

Also see note, to access the attribute, you must use the component getter syntax component.get("v.yourvarname").

To turn into a javascript variable in your controller or helper, do this:

let contacts = component.get("v.contactList");

If you examined this in the console you would see this is still a Proxy object, but if you attempted to access a property, it would be available, ie:

let fname = contacts[0].firstName;

Would work fine.

2

Using + when either side is a string, causes toString to be called on the other parameter, because JavaScript presumes you want string concatenation.

By way of example:

let x = 1 + '1' // '11'
let y = 1 + 1 // 2

Use , instead to make them separate parameters:

console.log('contacts', contactList);

This will give you a more desirable output, especially if you're using the new Lightning Web Security feature.

2
  • That's a nice insight. Reason I didn't suggest that they were using Web Security was because I think it's not enabled for Aura components. But I like that console trick. Mar 12, 2022 at 0:11
  • @CasparHarmer Yeah, LWS appears to be LWC only. That's a bummer. I guess one more reason to move to LWC sooner than later.
    – sfdcfox
    Mar 12, 2022 at 0:30

You must log in to answer this question.

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