[Vuejs]-Format Datetime from array using momentjs

2πŸ‘

βœ…

I think order is an array, you need to loop through it

responseAdapter: ({ order, totalItems }) => {
  const formatOrder = order.map(o => {
    const orderCopy = JSON.parse(JSON.stringify(o))
    orderCopy.orderDate = moment(o.orderDate).format('MMMM Do YYYY')
    return orderCopy
  })
  return {
    data: formatOrder,
    count: totalItems
  };
}

If you’re using ES6, there is shorter syntax

const formatOrder = order.map(o => {
  const orderDate = moment(o.orderDate).format('MMMM Do YYYY')
  return {...o, orderDate}
})
πŸ‘€ittus

Leave a comment