0

I'm trying to assign a value from my axios' response to a variable. How do I assign ContactID to a variable to use further?

my axios response:

{"0":{"Type":"ACCREC","Contact":{"ContactID":"b612f859-b9ea-4b98-a888-f0a666f859d4","AccountNumber":"TestingSylvester","ContactStatus":"ACTIVE","Name":"Testing }}}

my axios request:

.then(function (response) {
  console.log(JSON.stringify(response.data));
  this.axiosResponse.push(JSON.stringify(response.data));

})
.catch(function (error) {
  console.log(error);
});

I tried this, but I get the error: "Cannot read property 'axiosResponse' of undefined"

Jeandre
  • 3
  • 3
  • Most likely `this` is not bound, which would explain the error message you are getting. Check https://stackoverflow.com/questions/51805334/how-can-i-retrieve-a-reference-to-this-in-a-promise-then – mynd Apr 12 '21 at 13:38
  • @mynd you were correct. An arrow function immediately solved my issue, thanks! – Jeandre Apr 13 '21 at 02:04
  • I've added my comment as answer. Would be nice if you could accept it. – mynd Apr 13 '21 at 04:00

2 Answers2

0

You have not defined axiosResponse anywhere. All you have declared is the function parameter named response. hence you get the error message you described.

FrankPl
  • 919
  • 3
  • 12
0

Most likely this is not bound, which would explain the error message you are getting. Check how can I retrieve a reference to this in a promise.then ()?

mynd
  • 786
  • 5
  • 8