我有一个这样的对象:
obj = [{x:150, y:260},{x:160, y:545},{x:478, y:858},{x:125, y:560}]
Run Code Online (Sandbox Code Playgroud)
我想要一个这样的数组:
array = [150,260,160,545,478,858,125,560]
Run Code Online (Sandbox Code Playgroud)
我能怎么做 ?
使用 flatMap()
const obj = [{x:150, y:260},{x:160, y:545},{x:478, y:858},{x:125, y:560}]
const res = obj.flatMap(Object.values)
console.log(res)Run Code Online (Sandbox Code Playgroud)