0

Which the best way to convert this array object:

a = [
  {"id" : 1, "name": "a"},
  {"id" : 2, "name": "b"},
  {"id" : 3, "name": "c"}
]

to:

b = [
   [1, "a"],
   [2, "b"], 
   [3, "c"]
]
0

4 Answers 4

2
let b = a.map((ite)=>[ite.id,ite.name])
Sign up to request clarification or add additional context in comments.

Comments

2

With map method and Object.values

let newArr = a.map(x => Object.values(x));

Comments

1

map each element using Object.values.

const  a = [
 {"id" : 1, "name": "a"},
 {"id" : 2, "name": "b"},
 {"id" : 3, "name": "c"},
]
const b = a.map(Object.values);
console.log(b);

Comments

1

Using map

a = [ {"id" : 1, "name": "a"}, {"id" : 2, "name": "b"}, {"id" : 3, "name": "c"} ]
r=a.map(o=>[o.id,o.name])
console.log(r)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.