简体   繁体   English

循环返回结果 node.js

[英]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?我该怎么做?

If you're just trying to log all the choices, you can use a forEach loop如果您只是想记录所有的选择,您可以使用forEach循环

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

Try this尝试这个

 completion.data.choices.forEach(item => {
        console.log(item.text)
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM