我有一个看起来像这样的api
{
object1: [
0: Object {object keys and values}
1: Object {object keys and values}
2: Object {object keys and values}
],
object2: [
0: Object {object keys and values}
1: Object {object keys and values}
2: Object {object keys and values}
],
...
}
除非使用object1[0]
,否则我不知道如何访问对象的属性。这是我代码的其余部分。我尝试使用map(),但得到了第一个键的数组
axios
.get(
'http://apiUrl',
config
)
.then(response => {
console.log(
Object.keys(response.data).map(key => ({
key: `${key}`
}))
);
console.log(response.data);
console.dir(Object.keys(response.data));
})
.catch(error => {
this.setState({ error, isLoading: false });
console.log(error.response);
});
感谢所有可以帮助我的人