The data is coming from Controller like Map<String,List<String> and need to read the Map in the Javascript. I tried to use keyset() to get key, but it failed.
Original data in the Map is :
{"error":["Error Fields: (FirstName) : FirstName required.","Error Fields: (Phone) : Office Phone Number Required.","Error Fields: () : House Phone number required"]}
In the above data, I wanted to loop the value List based on Key 'error'.
Edit
The above issue resolved by using the below solution. But now I have an issue to display the error message line by line in the HTML page. I used to divide the error message by using \n but and print in the console, it looks good. But when I pass to the HTML, it is again showing next to each other. Here is the code.
result['error'].forEach( x=>{
errMsg += x+ '\n';
});
this.showErrorMessage = true;
Result in console:
errorMessage*****
FirstName Required.
Office Phone Number Required.
House Phone number required
But when displaying in HTML, it is displaying next to each other like this: FirstName Required. Office Phone Number Required. House Phone number required.
HTML code:
<template if:true={showErrorMessage}>
<div>
<h6 style="color: red;">{errMsg }</h6>
</div>
</template>