数组的形式为:
tagsList: [
0: "horm"
1: "MENEGHELLO PAOLELLI ASSOCIATI"
2: "Sideboards"
3: "Lacquered Sideboards"
4: "Contemporary Style Sideboards"
5: "Sideboards with doors"
];
如何通过 JavaScript 将此数组转换为另一种形式?
tagsList: [
{
id: 0,
text: "horm"
}
{
id: 1,
text: "MENEGHELLO PAOLELLI ASSOCIATI"
}
{
id: 2,
text: "Sideboards"
}
{
id: 3,
text: "Lacquered Sideboards"
}
{
id: 4,
text: "Contemporary Style Sideboards"
}
{
id: 4,
text: "Sideboards with doors"
}
];
没有它array.map((item, index) => [{id: index, text: item}])
就会[]
产生错误。出现此响应:
在数组上调用map函数,并在回调中返回对象,例如