my problem is quite simple, I would like to put hashtags in a text from a list of them.
I have tried every way but I can’t find the solution.
Thanks in advance.
let arr = ['aa', 'bb']
let caption = `Hello | World `;
arr.forEach(el => {
console.log(`#${el}`)
caption.concat(' ', `#${el}`)
});
console.log(caption) // I want : "Hello | World #aa #bb" ; But it puts me "Hello | World"
>Solution :
concat does not modify the original string. You have to assign the returned value of concat back to caption.
let arr = ['aa', 'bb']
let caption = `Hello | World `;
arr.forEach(el => {
console.log(`#${el}`)
caption = caption.concat(' ', `#${el}`)
});
console.log(caption) // prints : "Hello | World #aa #bb"