+ Start a Discussion
Kishore Vamsi 6Kishore Vamsi 6 

How to get first value in list of strings in LWC

I want to capture first values in list of string using js controller. my apex getListofString returning list strings.

 
nameList =[];
firstValue='';
getListofString().then(data => {
                this.nameList = data;
               this.firstValue=?
                
        })
SwethaSwetha (Salesforce Developers) 
HI Kishore,
Does using  this.firstValue=data[0] work for your scenario?The below articles might help:
https://salesforce.stackexchange.com/questions/271003/accessing-single-element-of-list-from-apex-in-lwc
https://salesforce.stackexchange.com/questions/264631/lwc-how-to-handle-null-situation-before-the-data-is-loaded-from-controller?rq=1

Thanks