How can I strip the data:image part from a base64 string of any image type in Javascript
You can use a regular expression:
var strImage = strToReplace.replace(/^data:image\/[a-z]+;base64,/, "");
^
means At the start of the stringdata:image
means data:image\/
means /[a-z]+
means One or more characters between a and z;base64,
means ;base64,
var solution = string.split("base64,")[1];
Splits the variable string at "base64," than take the second part.
This worked for me :
var strImage = strToReplace.split(',')[1];