How can I make an empty string array in Typescript?
Outside of a method:
arr: string[] = [];
The definition of string array should be:
// instead of this
// var errors: [string];
// we need this
var errors: string[];
errors = [];
Note: another issue could be the parameter key here
...forEach(function (key) {...
I would guess that we often should declare two of them, because first is very often value, second key/index
Object.keys(response.data.modelState)
.forEach(function (value, key) {
errors.push.apply(errors, response.data.modelState[key]);
});
And even, we should use arrow function, to get the parent as this
Object.keys(response.data.modelState)
.forEach( (value, key) => {
errors.push.apply(errors, response.data.modelState[key]);
});
Missing an obvious answer, needed when not assigning it to a variable: [] as string[]