How can I remove some texts from a string which is inside of an object and object is in the array?

How can I remove description:("Auto-generated by YouTube.") from title?

[
  {
    title: 'DÁKITI description:("Auto-generated by YouTube.")',
    author: 'Bad Bunny',
    duration: 205090
  }
]

Thanks in advance!

3 thoughts on “How can I remove some texts from a string which is inside of an object and object is in the array?”

  1. use map array method, i guess you have other elements in the array with the same substring, then for each one use replace string method:

    let data = [
      {
        title: 'DÁKITI description:("Auto-generated by YouTube.")',
        author: 'Bad Bunny',
        duration: 205090
      }
    ]
    
    let result = data.map(e => ({...e,title:e.title.replace('description:("Auto-generated by YouTube.")','').trim()}))
    
    console.log(result)
    Reply
  2. I hope this is usefull for uh .Using the map method and replace value .

    const data = [
      {
        title: 'DÁKITI description:("Auto-generated by YouTube.")',
        author: 'Bad Bunny',
        duration: 205090
      }
    ];
    
    const replacedata = data.map(m => {
      m.title = m.title.replace('description:("Auto-generated by YouTube.")', "").trim();
      return m;
    })
    
    console.log('data ', replacedata)
    Reply

Leave a Comment