gpt4 book ai didi

javascript - 如何在 React Native 上访问数组状态或 json 数据?

转载 作者:行者123 更新时间:2023-11-30 14:30:33 24 4
gpt4 key购买 nike

我有状态

data: [
{ 'keya': 'Quando analisa','index':0 },
{ 'keyb': 'Modelo de texto','index':1 },
{ 'keyc': 'Parte sofreu alteraes','index':2 },
{ 'keyd': 'Todos os geradores','index':3 },
],

想要访问索引。尝试过

this.state.data.index

但没有得到索引值。如何访问索引?

最佳答案

您的 this.state.data 是一个数组,因此您需要遍历该数组以获取索引值并使用它来访问具有 index 的所有对象属性如:

for(var i=0; i<this.state.data.length; i++){
console.log(this.state.data[i].index);
}

或者你需要显式定义索引值作为this.state.data[0].index来获取索引0处对象的index 等等。

关于javascript - 如何在 React Native 上访问数组状态或 json 数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51266113/

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