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!
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!
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)
If you have an array with multiple objects with the auto generated description you can use forEach
and update the title attribute of each element.
forEach will not create a new array like map will do, it will simply update your existing array.
data.forEach(e => {
e.title = e.title.replace('description:("Auto-generated by YouTube.")', '');
})
let data = [{
title: 'DÁKITI description:("Auto-generated by YouTube.")',
author: 'Bad Bunny',
duration: 205090
}]
data.forEach(e => {
e.title = e.title.replace('description:("Auto-generated by YouTube.")', '');
})
console.log(data)