Omi*_*cat 3 javascript arrays object node.js
我怎样才能转换Array这个Objects
var tags= [
{id: 0, name: "tag1", project: "p1", bu: "test"},
{id: 1, name: "tag2", project: "p1", bu: "test"},
{id: 2, name: "tag3", project: "p3", bu: "test"}
];
Run Code Online (Sandbox Code Playgroud)
进入这个 2d array:
[["tag1","p1", "test"],
["tag2","p1", "test"],
["tag3","p3", "test"]]
Run Code Online (Sandbox Code Playgroud)
你可以使用map
var tags= [ {id: 0, name: "tag1", project: "p1", bu: "test"}, {id: 1, name: "tag2", project: "p1", bu: "test"}, {id: 2, name: "tag3", project: "p3", bu: "test"} ];
var res=tags.map(o=>[o.name,o.project,o.bu])
console.log(res)Run Code Online (Sandbox Code Playgroud)
或者你可以使用更通用的方法
var tags= [ {id: 0, name: "tag1", project: "p1", bu: "test"}, {id: 1, name: "tag2", project: "p1", bu: "test"}, {id: 2, name: "tag3", project: "p3", bu: "test"} ];
var res = tags.map(({id,...rest}) => Object.values(rest))
console.log(res)Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2294 次 |
| 最近记录: |