[javascript] Replace last occurrence of character in string

This is very similar to mplungjan's answer, but can be a bit easier (especially if you need to do other string manipulation right after and want to keep it as an array) Anyway, I just thought I'd put it out there in case someone prefers it.

_x000D_
_x000D_
var str = 'a_b_c';_x000D_
str = str.split(''); //['a','_','b','_','c']_x000D_
str.splice(str.lastIndexOf('_'),1,'-'); //['a','_','b','-','c']_x000D_
str = str.join(''); //'a_b-c'
_x000D_
_x000D_
_x000D_

The '_' can be swapped out with the char you want to replace

And the '-' can be replaced with the char or string you want to replace it with