gpt4 book ai didi

javascript - 如何将变量分配给 API 调用中的解构数据?

转载 作者:行者123 更新时间:2023-12-02 22:50:38 26 4
gpt4 key购买 nike

如果我有,

let results = null;

try {
const {
hits: { hits: queryAsAWhole }
} = await client.search({
q:
"a AND b AND c AND d AND e AND f AND G AND H"
});

如何将 queryAsAWhole 分配给一次调用中的结果而不执行任何操作,

let results = null;

try {
const {
hits: { hits: queryAsAWhole }
} = await client.search({
q:
"a AND b AND c AND d AND e AND f AND G AND H"
});

results = queryAsAWhole;

作为一个类轮?

最佳答案

您已经使用 querAsAWhile 作为 hits 的别名,您可以使用 results 作为别名:

const {
hits: { hits: results }
} = await client.search({

results 将具有来自 IIFE 的返回值:

let results = (() => {
try {
const obj = {
hits: {
hits: "hello"
}
};

const {
hits: { hits: queryAsAWhole }
} = obj;

return queryAsAWhole;
} catch (e) {
return e;
}
})();

console.log(results);

关于javascript - 如何将变量分配给 API 调用中的解构数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58190097/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com