It is ok to retrieve the elements of a List<String> in Javascript controller in LWC as below:
@wire(getListOfString)wrappers({error, data}) {
if(data){
this.stringList = data;
this.str0 = data[0];
this.str1 = data[1];
this.str2 = data[2];
}else{
this.error = error;
}
}
And it is ok to display {str0}, {str1}, {str2} in the HTML file.
In other words, {stringList} is a List<String> and it works well in the Javascript controller.
But, it does not work in the HTML file.
I've tried to use {stringList[0]}, {stringList[1]}, {stringList[2]} in the HTML file directly. And, it is not ok.
It is not ok to use {stringList}[0], {stringList}[1], {stringList}[2], neither.
Could it be able to retrieve the element from List in HTML file directly? Or, it can not work in this way.
== Use case ==
Think of a use case for which the output of LWC depends on serval factors. In the case, I prefer to retrieve those factors to a List with a single Apex class.
And, if the conventions support {strings[n]} syntax in the template file, (where {string[n]} is a specific factor) then it will be easiler to control the dynamic/factor-dependent LWC.
Best Answer
You can use
for:each
for this.But you cannot use expressions in LWC templates. for eg:
{strings[0]}
or{strings}[0]
is NOT ALLOWED