Search code examples
javascriptbracketssquare-bracket

Javascript remove last square brackets [ ] in string


How to remove last square brackets. I have string like this:

Product[parameter][0][values][2][value]

And I need to achive string without last brackets:

Product[parameter][0][values][2]

Solution

  • Try like this:

    var x = "Product[parameter][0][values][2][value]";
    x = x.substr(0, x.lastIndexOf("["));
    alert(x);
    

    JSFIDDLE DEMO