When using .map() to transfer object fields from one JSON List to another, I encountered an issue with the starting list having spaces in the field names.
The process works smoothly for fields without spaces, like this:
$scope.dataList = results.data.map(el => ({
IdApplication: el.ApplicationReference,
AccNo: el.AccountNumber
}))
However, the initial JSON data is directly sourced from a CSV chosen by the user, and the client insists on keeping column names with spaces. This means I have to map a JSON field named 'Application Reference'.
I attempted enclosing the field name in '', but that resulted in an identifier expected error upon encountering the opening '.
Even trying bracket notation led to complications:
$scope.dataList = results.data.map(el => ({
IdApplication: el.['Application Reference'],
AccNo: el.AccountNumber
}))
This approach also triggered an identifier expected error with the opening [.