carol1287
carol1287

Reputation: 395

grab specifc value from a string

Does anyone know how could I get the image URL from a string? I may get 2 URL's or more than two delimited by a comma and some of them won't not be an image.

 var sample_str = "http://domain.com/test.html,http://another.domain.com/images/1234.jpg";

Basically what I want to do is get only the image URL and omit the rest.

 http://another.domain.com/images/1234.jpg

Upvotes: 1

Views: 41

Answers (1)

Anthony Horne
Anthony Horne

Reputation: 2522

Use split and run through the values. Along the lines of:

var s = "http://domain.com/test.html,http://another.domain.com/images/1234.jpg";
var ss = s.split(",");
for (var i=0; i<ss.length; i++) {
//for (var i in ss) {
    document.write(ss[i]);
    document.write("<br/>");
}

Upvotes: 1

Related Questions