Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove last comma from string using jQuery

I am using the Supersized jQuery plugin and need to remove the last comma from the list of images so it works in IE. The Supersized plugin does not work in IE if there is a comma after the last image, this is a known issue.

I am using Business Catalyst, so this is not PHP.

This is how the list of images appear, with a trailing comma:

{image : 'melbourne.jpg'},{image : 'tunnel.jpg'},{image : 'building.jpg'},

What would be the best way to do this?

    jQuery(function($){
            $.supersized({
                slide_interval          :   3000,       
                transition              :   1,          
                transition_speed        :   700,        

                slides                  :   [  // Slideshow Images  
                                               {module_webapps,9198,a template="/Layouts/WebApps/slide.tpl"}
                                            ]
            });
        });

And this is what /Layouts/WebApps/slide.tpl looks like. Basically just looping through the slider images...

{image : '{tag_bg image_value}'},
like image 682
user537137 Avatar asked Dec 03 '25 21:12

user537137


1 Answers

You can use regulare expression on your string like that :

var modifiedString = yourString.replace(/,\s*$/, '');

This will remove the last comma IF there is one and will also remove white space.

like image 169
Karl-André Gagnon Avatar answered Dec 05 '25 10:12

Karl-André Gagnon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!