I'm going to preface this with the fact that the JSON I am getting is coming from angular-csv-import and I am trying to clean up the strings within the keys, values.
I have read this thread but I don't want to to use JQuery so I edited to be in a more angular way.
Remove leading and trailing spaces in object keys and values
Here is the data I am getting from the CSV file
[
{
"TRAIN_LINE":"El",
" ROUTE_NAME":"Brown Line",
" RUN_NUMBER":"E102",
" OPERATOR_ID":"SJones"
},
{
"TRAIN_LINE":"Metra",
" ROUTE_NAME":"UPN",
" RUN_NUMBER":"M405",
" OPERATOR_ID":"AJohnson"
}
]
To send the data to my api I need it to have no leading or trailing spaces to minimize clean up and keep it consistent no matter what the csv file uploaded is.
I'm able to remove the space using .trim() on the keys and values but it is not updating in the dataset I am going to send to the server. Any help much appreciated. Here is my code in my controller.
$scope.postData = function (result) {
angular.forEach(result, function (index) {
angular.forEach(index, function (k, v) {
k = k.trim();
v = v.trim();
return k;
return v;
});
return index;
console.log(index);
});
console.log(result);
};
Note if I log k and v the spaces are removed, but how do I push that to the results.