I have a string like this
const text = 'hello ___ where ___ test ___'
And also an array like this
const blankData = ['there', 'you', 'it']
my expected result is
hello there where you test it
what i have tried
const result = text?.replaceAll('___', (index, x) => {
return blankData[index]
})
I also getting with not ellegant idea like this
const mapped = text
.split('___')
.map((textitself, index) => textitself + blankData?.[index])
mapped.pop()
const result = mapped.join('')
is there better solution?
im thinking of getting the index so i can replace for every index found but replace fould not getting index from it callback
