I have to find and replace the "b" with "g" in the image src attribute.
The initial src would be something like "someName-b.png", and with JavaScript, I have to replace the "b" with "g". But the problem is the "someName" can differ in length. So basically what I want to do is find the 5th character from the end of the src attribute string, and then replace the 5th char to "g".
Is there a function in JavaScript that allows me to find the xth character from the end of a string?
Find the 5th character from end of a String:
string.charAt(string.length - 5).Replace the 5th character from the end of a String:
string.substring(0, string.length -5) + 'g' + string.substring(string.length - 4)