Arrays 使用react中的map在数组中推送响应数组的索引
如何使用react中的map在数组或对象中存储响应数组对象的索引Arrays 使用react中的map在数组中推送响应数组的索引,arrays,reactjs,dictionary,object,Arrays,Reactjs,Dictionary,Object,如何使用react中的map在数组或对象中存储响应数组对象的索引 data: mat: opts: 0: {text: "1"} 1: {text: "2"} 2: {text: "3"} 3: {text: "4"} 4: {text: "5"} 5: {text: "6"} 6: {text: "7"}
data:
mat:
opts:
0: {text: "1"}
1: {text: "2"}
2: {text: "3"}
3: {text: "4"}
4: {text: "5"}
5: {text: "6"}
6: {text: "7"}
7: {text: "8"}
8: {text: "9"}
9: {text: "10"}
数组长度是固定的,即10。我找到了它
const element = props.data.mat.opts.map((el, i) => console.log(i));
它会回来的
0
1
2
3
4
5
6
7
8
9
我们可以将其存储在数组中
let arr = [];
const element = props.data.mat.opts.map((el, i) => arr.push(i));
你能告诉我你打算如何使用这些信息吗?可能还有另一种方法可以获取这些信息,而不是您所建议的方法。我只需要将索引0到9存储在一个数组中