我只想从arrayList下面删除一个额外的括号:
[
{
"small":"https://www.googleapis.com/photo.png?",
"medium":"https://www.googleapis.com/photo.png?",
"big":"https://www.googleapis.com/photo.png?"
},
[
{
"small":"https://www.googleapis.com/Jenner.jfif?",
"medium":"https://www.googleapis.com/Jenner.jfif?",
"big":"https://www.googleapis.com/Jenner.jfif?"
}
]
]
to
[
{
"small":"https://www.googleapis.com/photo.png?",
"medium":"https://www.googleapis.com/photo.png?",
"big":"https://www.googleapis.com/photo.png?"
},
{
"small":"https://www.googleapis.com/Jenner.jfif?",
"medium":"https://www.googleapis.com/Jenner.jfif?",
"big":"https://www.googleapis.com/Jenner.jfif?"
}
]
...............................................
答案 0 :(得分:2)
这样的东西?
将原始数组和maps每个元素放到一个新数组中。如果原始元素是一个数组(它有'额外的括号'),那么它不是复制值,而是复制该数组的第一个元素,有效地“删除括号”。我认为这就是你要找的东西。
var a = [
{
"small": "https://www.googleapis.com/photo.png?",
"medium": "https://www.googleapis.com/photo.png?",
"big": "https://www.googleapis.com/photo.png?"
},
[
{
"small": "https://www.googleapis.com/Jenner.jfif?",
"medium": "https://www.googleapis.com/Jenner.jfif?",
"big": "https://www.googleapis.com/Jenner.jfif?"
}
]
];
a = a.map(elem => {
if (elem.constructor === Array) {
return elem[0];
} else {
return elem;
}
});
console.log(a);