Tripati Subudhi Tripati Subudhi - 4 months ago 6
Javascript Question

How to get each value from a comma separated string in JavaScript?

Lets consider I have a string called

string s = "jpeg, jpg, gif, png";

So from this I need to get each one like, I can assign each extension to one var variable
such as

var a = jpeg
var b = jpg
var c = gif
var d = png

Same way if I will add more extensions to the string then accordingly I will have to get all with same var variable.


All you have to do is to use the javascript split method-

    var s = "jpeg, jpg, gif, png";
    var match = s.split(', ')
    for (var a in match)
        var variable = match[a]
<script src=""></script>