Change the casing title of the object inside an array

You can do this:

const listData = [
  {
      "title": "some_id",
      "dataTypes": "character varying(65535)"
  },
  {
      "title": "some_value",
      "dataTypes": "character varying(65535)"
  }
]

const newData = []
listData.map(el => newData.push({
  "title":el.title.split('_').map( word => {
    return word[0].toUpperCase() + word.substring(1, word.length);
  }).join(' '),

  "dataTypes" : el.dataTypes }))
console.log(newData);

You will have to iterate through the split title and update the first letter.

The result is:

[ { title: 'Some Id', dataTypes: 'character varying(65535)' },
  { title: 'Some Value', dataTypes: 'character varying(65535)' } ]

One solution would be to implement a captilization function for a word as follows:

word => `${word.substring(0,1).toUpperCase()}${ word.substring(1)}`

This could be integrated with your existing code as shown below:

const listData = [{
    "title": "some_id",
    "dataTypes": "character varying(65535)"
  },
  {
    "title": "some_value",
    "dataTypes": "character varying(65535)"
  }
]

const result = listData.map(item => {
  
  return {
    dataTypes : item.dataTypes,
    title : item.title
        .split('_')
        .map(word => `${word.substring(0,1).toUpperCase()}${ word.substring(1)}`)
        .join(' ')
  }
  
});

console.log(result);


You were close. The are multiple ways you can capitalize words and one of the ways is using regex which will only capitalize letters.

"will 101skip that".replace(/\b[a-z]/g, match => match.toUpperCase());

const listData = [
        {
            "title": "some_id",
            "dataTypes": "character varying(65535)"
        },
        {
            "title": "some_value",
            "dataTypes": "character varying(65535)"
        }
  ]
  const newData = []
  listData.map(el => newData.push({"title":el.title.split('_').join(' ').replace(/\b[a-z]/g, match => match.toUpperCase()),"dataTypes" : el.dataTypes }))
  console.log(newData);