SyntaxFix
Write A Post
Hire A Developer
Questions
Well, if the string really ends with the pattern, you could do this:
str = str.replace(new RegExp(list[i] + '$'), 'finish');