乐趣区

数据格式处理

let objectTest = [{"instanceClass":"AAAAA"},
    {"instanceClass":"BBBBB"},
    {"instanceClass":"CCCCC"}
]

问题:将 objectTest 数据格式改为 [“AAAAA”,”BBBBB”,”CCCCC”]
答:

1、let testArray = Array.from(objectTest,({instanceClass})=> instanceClass);
console.log(testArray); //[["AAAAA","BBBBB","CCCCC"]]
2、let testArray1 = objectTest.map((item)=> Object.values(item)[0] )
console.log(testArray1); //[["AAAAA","BBBBB","CCCCC"]]
退出移动版