How can I strip the data:image part from a base64 string of any image type in Javascript
<p>I am currently doing the following to decode base64 images in Javascript:</p>

<pre><code>    var strImage = "";
    strImage = strToReplace.replace("data:image/jpeg;base64,", "");
    strImage = strToReplace.replace("data:image/png;base64,", "");
    strImage = strToReplace.replace("data:image/gif;base64,", "");
    strImage = strToReplace.replace("data:image/bmp;base64,", "");
</code></pre>

<p>As you can see above we are accepting the four most standard image types (jpeg, png, gif, bmp);</p>

<p>However, some of these images are very large and scanning through each one 4-5 times with replace seems a dreadful waste and terribly inefficient.</p>

<p>Is there a way I could reliably strip the data:image part of a base64 image string in a single pass? </p>

<p>Perhaps by detecting the first comma in the string?</p>

<p>Thanks in advance.</p>