我有一个这样的对象结构:
vKzGBlblU7hVqIildUIb:
characters: (2) [{â¦}, {â¦}]
created_by: "test1234"
deleted_at: null
genre: ""
key: "vKzGBlblU7hVqIildUIb"
main_character: ""
number_of_characters: 2
status: "draft"
summary: "Summary 23"
title: "Titile 23"
uploaded_at: 1531686836601
我试图用
Object.keys
但我最终在一个数组中有两个对象。一个包含内部数组的
characters
另一个不包含数组的对象
字符
是的。我得到这样的东西。
0:
characters: (2) [{â¦}, {â¦}]
created_by: "test1234"
deleted_at: null
genre: ""
key: "vKzGBlblU7hVqIildUIb"
main_character: ""
number_of_characters: 2
status: "draft"
summary: "Summary 23"
title: "Titile 23"
uploaded_at: 1531686836601
1:
created_by: "test1234"
deleted_at: null
genre: ""
key: "vKzGBlblU7hVqIildUIb"
main_character: ""
number_of_characters: 2
status: "draft"
summary: "Summary 23"
title: "Titile 23"
uploaded_at: 1531686836601
这就是我试图将对象转换为数组的方式。
const array = Object.keys(objs).map((obj, index) => {
return objs[obj]
});
我不明白我做错了什么有什么建议吗?
更新:
对象结构很简单:
{
vKzGBlblU7hVqIildUIb: {
characters: [{
name: "",
id: ""
}]
key: "vKzGBlblU7hVqIildUIb"
//other props listed in the example above
}
irufsxKuw9I20pLDa6P7: {
characters: [{
name: "",
id: ""
}]
key: "irufsxKuw9I20pLDa6P7"
//other props listed in the example above
}
// so on
}
我所期望的
对象.keys
可以做到:
[
0: {
characters: [{
name: "",
id: ""
}]
key: "vKzGBlblU7hVqIildUIb"
//other props listed in the example above
}
1: {
characters: [{
name: "",
id: ""
}]
key: "irufsxKuw9I20pLDa6P7"
//other props listed in the example above
}
// so on
]
但实际上发生了什么:
[
0: {
characters: [{
name: "",
id: ""
}]
key: "vKzGBlblU7hVqIildUIb"
//other props listed in the example above
}
1: {
characters: [{
name: "",
id: ""
}]
key: "irufsxKuw9I20pLDa6P7"
//other props listed in the example above
}
2: {
key: "vKzGBlblU7hVqIildUIb"
//other props listed in the example above
}
3: {
key: "irufsxKuw9I20pLDa6P7"
//other props listed in the example above
}
// so on
]
对象被复制一次使用嵌套数组,另一次不使用。我只是不想要这个复制品。