I have the following variable
var brands = [];
Which I need to populate with some data. The data is comming from an API. I use Axios
to perform a GET
.
getRemoteBrands() {
axios
.get("http://my-url")
.then(response => {
response.data.forEach(element => {
var instance =
{
label: element.brand,
value : element.brand
};
this.brands.push(instance);
});
}).catch(error => console.log(error));
}
The following error is show in developer tools
TypeError: Cannot read property 'push' of undefined
at index.js:104
at Array.forEach (<anonymous>)
at index.js:98
Obviously brands
is not an array
, but an object. How can I make this an array
?