0

I've got a piece of javascript that dynamically calls an image URL

if (searchResult['image'] != undefined) {
                    if (searchResult['link'] != undefined) {
                        searchResultNode += '<a class="image" href="' + searchResult['link'] + '">';
                    }

                    searchResultNode += '<img src="' + searchResult['image'] + '" class="ss360-search-result-image" />';

                    if (searchResult['link'] != undefined) {
                        searchResultNode += '</a>';
                    }

                }

What function can I write to edit the img src URL so that it removes the file name suffix (.png, .jpg, .jpeg), adds '-764x375' to the URL, and then readds the filename suffix?

3
  • What if the image doesn't have a suffix? Commented Mar 11, 2017 at 14:37
  • 1
    If you can always rely on there being a suffix, you could replace every occurrence of e.g. .jpg by -764x375.jpg if it occurs at the end of the string. See e.g. stackoverflow.com/questions/2729666/… Commented Mar 11, 2017 at 14:38
  • You can split the string at the last index of . to getan array and you know what to do next. Commented Mar 11, 2017 at 14:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.