0

I'm trying to read the promise response data which is seen as below in my console. How can i get business_id from the response. I tried using below code but it returned null:

let product = Api.get('materials/'+p.id).catch(() => {}).then((data)=>{return data.business_id;});

enter image description here

charlie2
  • 150
  • 2
  • 10
  • `.then`, or `async`/`await` [Guide to using promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises) – Bravo Mar 15 '22 at 04:57
  • I tried but i didn't work. May be i did something wrong please help me. I have updated code above. – charlie2 Mar 15 '22 at 05:09
  • `const { business_id: product } = await Api.get(\`materials/${p.id}\`);` – Phil Mar 15 '22 at 05:11
  • 1
    you tried what? using `.then` or `asynv/await`? you did it right ... because `.then((data)=>{return data.business_id;})` ... which means now the **Promise** returned will resolve to the `buesiness_id` ... you still need to understand how to work with Promises as per link above - you can't get synchronous results from asynchronous code – Bravo Mar 15 '22 at 05:15

0 Answers0