skip to Main Content
A = [{"name":"John","age":30,"city":"New York"},{"name":"Jimmy","age":40,"city":"Toronto"}]

B = [["John", 30, "New York"], ["Jimmy", 40, "Toronto"]]

How to convert A into B in JavaScript?

Thanks in advance for your help!

2

Answers


  1. const A = [{"name":"John","age":30,"city":"New York"},{"name":"Jimmy","age":40,"city":"Toronto"}];

    const B = A.map(item => [item.name, item.age, item.city]);

    console.log(B);

    Login or Signup to reply.
  2. simply:

    const
      A = 
        [ { name: 'John',  age: 30, city: 'New York' } 
        , { name: 'Jimmy', age: 40, city: 'Toronto'  } 
        ] 
    , B = A.map( Object.values ) // or A.map( r => Object.values(r) )
      ;
      
    console.log( B );
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search