I have a JavaScript function that makes an ajax call to an API, and gets a JSON array.
Here is a sample of an array that I get:
[
{
"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
}
]
}
]
I put it into a JavaScript array:
$scope.CorrectionDatas = ResponseFromApi;
So, for each ErrorType, I have some "explanations". I would like to add another property, in order to have something like this :
[
{
"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 though that I could do it only by doing it like that:
$scope.CorrectionDatas.forEach(function (error) {
error.push({ show: true });
});
But my debugger gives me an error:
Error: error.push is not a function
$scope.getErrors/</<@http://localhost:1771/dependencies/local/js/Correction/CorrectionCtrl.js:26
{"ErrorType":"Warnings", "Explanations":[{ Blablabla, I think there's already much here }]}is an object...