yandex
loader

please wait

  • Jadav Payeng Mar-14-2019 06:40:20 AM ( 1 week ago )

     

    I am trying to convert this array

    let orders = [
      {  amount: '100', user: 'admin', date: 'March 6, 2019' },
      {  amount: '120', user: 'admin', date: 'March 6, 2019' },
      {  amount: '80', user: 'admin', date: 'March 7, 2019' },
      {  amount: '200', user: 'admin', date: 'March 7, 2019' },
    ];

    to something like this

    orders = [
      ['100', 'admin', 'March 6, 2019'],
      ['120', 'admin', 'March 6, 2019'],
      ['80', 'admin', 'March 7, 2019'],
      ['200', 'admin', 'March 7, 2019'],
    ];

    and I have read that Objects.values() returns the values in an array, so I tried to iterate through the order array by using forEach() and using the Object.values on each item in the array.

    let newOrders = orders.forEach(order => {
      return Object.values(order);
    });

    I don't know if what I am doing is right and I am new to Javascript. Please help me.

  • Imran Malik Mar-14-2019 06:42:16 AM ( 1 week ago )

    Simply use orders.map(Object.values)

    let orders = [
      {  amount: '100', user: 'admin', date: 'March 6, 2019' },
      {  amount: '120', user: 'admin', date: 'March 6, 2019' },
      {  amount: '80',  user: 'admin', date: 'March 7, 2019' },
      {  amount: '200', user: 'admin', date: 'March 7, 2019' },
    ];
    
    const result = orders.map(Object.values);
    
    console.log(result)

Please login

Similar Discussion

Recommended For You