Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
Lodash: replace value in array of objects

To replace value in array of objects, and in this case the created_at with 'jan', 'Feb' etc, I can certainly use map through as shown below.

But is there a shorter way using lodash?

import React, { useEffect } from 'react'
import _ from 'lodash'
import moment from 'moment'

interface DataProps {
  clazz_name: string
  created_at: string
}

const dataone: DataProps[] = [
  {
    clazz_name: '1A',
    created_at: '2022-01-19T09:13:42.149+08:00',
  },
  {
    clazz_name: '1B',
    created_at: '2022-02-19T09:13:42.149+08:00',
  },
]

let datatwo: DataProps[] = []

function App() {
  useEffect(() => {
    dataone.forEach((item) =>
      datatwo.push({
        clazz_name: item.clazz_name,
        created_at: moment(item.created_at).format('MMM'),
      })
    )
    console.log(datatwo)
  }, [])

  return <div>Test</div>
}

export default App

Any hint or help would be greatly appreciated.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use _.map like below

const dataTwo = _.map(dataOne, item => ({...item, created_at: moment(item.created_at).format('MMM') }))
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!