I am currently working on a JavaScript function that utilizes an ajax call to retrieve data from an API in the form of a JSON array.
Here is a snippet of the array structure that I receive:
[
{
"ErrorType": "Errors",
"Explanations": [
{
"Explanation": "Price Missing",
"Locations": [
25,
45
]
},
{
"Explanation": "Unit of measurement not valid",
"Locations": [
25,
301,
302
]
}
]
},
{
"ErrorType": "Warnings",
"Explanations": [
{
Blablabla,
Ithinkthere's already much here
}
]
}
]
After fetching the data, I store it in a JavaScript array like so:
$scope.CorrectionDatas = ResponseFromApi;
My goal is to enhance this array by adding a new property for each 'ErrorType', resulting in the following structure:
[
{
"ErrorType": "Errors",
"Explanations": [
{
"Explanation": "Price Missing",
"Locations": [
25,
45
]
},
{
"Explanation": "Unit of measurement not valid",
"Locations": [
25,
301,
302
]
}
],
"show": true
},
{
"ErrorType": "Warnings",
"Explanations": [
{
Blablabla,
Ithinkthere's already much here
}
],
"show":true
}
]
I attempted to achieve this by using the following approach:
$scope.CorrectionDatas.forEach(function (error) {
error.push({ show: true });
});
However, upon running my code, I encountered the following debugger error:
Error: error.push is not a function
$scope.getErrors/</<@http://localhost:1771/dependencies/local/js/Correction/CorrectionCtrl.js:26