gpt4 book ai didi

javascript - 如何将变量 X 替换为数组索引 0 处的数据,其值为 'X'

转载 作者:行者123 更新时间:2023-12-01 00:14:15 25 4
gpt4 key购买 nike

    this.work[0].minValue = await this.getData().then(
value => value[0].set.min.X
)
this.work[1].minValue = await this.getData().then(
value => value[0].set.min.Y
)
this.work[2].minValue = await this.getData().then(
value => value[0].set.min.Z
)
this.work[3].minValue = await this.getData().then(
value => value[0].set.min.A
)
this.work[4].minValue = await this.getData().then(
value => value[0].set.min.B
)
this.work[5].minValue = await this.getData().then(
value => value[0].set.min.C
)

我试图在循环内编写这 6 行代码,但我无法做到。有人可以帮我吗?

var arr = ['X', 'Y', 'Z', 'A', 'B', 'C']
var i = 0
var that = this
this.work.forEach(item => {
item.minValue = that.getData().then(value => value[0].set.min.that.arr[i])
i++
})

我知道 min.that.arr[i] 这是错误的。请不要说出它不起作用的原因,请帮我解决问题。

最佳答案

value[0].set.min[arr[i]]

ashkan 的建议解决了我的问题。

关于javascript - 如何将变量 X 替换为数组索引 0 处的数据,其值为 'X',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59874071/

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