javascript – 将对象数组转换为数组数组
作者:互联网
var json = [{one: "text1", two: "text2", three: 3, four: 4},
{one: "text3", two: "text4", three: 5, four: 6},
{one: "text5", two: "text7", three: 8, four: 9}]
如何将上面的对象数组转换为下面的数组数组?
var array = [["text1", "text2", 3, 4],
["text3", "text4", 5, 6],
["text5", "text7", 8, 9]]
是否有ES2015功能可以轻松转换?如果不是for循环可能会.
解决方法:
你可以使用map和Object.values
let array = json.map(obj => Object.values(obj));
标签:javascript,ecmascript-6,javascript-objects 来源: https://codeday.me/bug/20190928/1825220.html