Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

loop through returned results node.js

I am getting results returned from my request made to my server. It is returning multiple lines, in which each line is a new entry into the array.

So right now I am logging it as:

completion.data.choices[0].text

and it is obviously only returning the first one. But i want it to return all of them. How would I do this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you’re just trying to log all the choices, you can use a forEach loop

completion.data.choices.forEach(choice => {
  console.log(choice.text);
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading