Question: I have an attribute of type CustomSetting\_\_c(which is a list type of CUSTOM SETTING) and I want to iterate over it to fetch its each record, and print that record's certain fields. I am unable to iterate over it and '.length' property is givng me error as:

> 
> [Cannot read property 'length' of undefined]
> 
> 
> 

Please find related code:

> 
> Lightning component attribute:
> 
> 
> 

```
<aura:attribute name="customSettingList" type="CustomSetting__c[]" />

```

On click of certain button, I want to go to helper of this component and execute this code:

> 
> Helper.js:
> 
> 
> 

```
//some code before this
component.set("v.customSettingList", response.getReturnValue());
//some code after this statement

    var customSettingList=[];
    customSettingList=component.get("v.customSettingList");
    for(var i=0;i<customSettingList.length;i++){
        console.log('customSettingList type: '+ customSettingList[i].Type__c);
    }  

```

where Type\_\_c is a custom field of this custom setting.

What is the reason for this? How can I access the field values of individual records from list? 

Note: This is a list type of custom setting if that has to do anything with this.(Can we not access list custom setting in JS?)

Answer: 
The issue you are facing here is the fact that your customSettingList is undefined.
This means you have not assigned any values to it.

This being said I'm missing the part where you are actually fetching the custom settings list.

Simply declaring this on your component is not sufficient:

```
<aura:attribute name="customSettingList" type="CustomSetting__c[]" />

```

The above code is simply telling lightning/aura that your component has an attribute of type CustomSetting\_\_c[]. By default this attribute has no values assigned, nor is lightning capable of doing this for you.
You will need to access the server yourself in order to get the list of custom settings and assign it to your attribute. You can do this by adding an Apex controller to your component.

More details can be found here:
<https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/apex_intro.htm>
I think I got it. It was because the part where I set the array using set() was in callback and the code where I was printing using component.get() was called before this callback, though it was after it in the flow. Since it was callback, the value was not set till the time I was trying to access it