Javascript substring, slice not working

158 views Asked by At

I am trying to chop the last ; off an array that has been converted to a string.

Substring and slice don't appear to be doing this?

The two pieces of data i get back are below, but i can remove that last ;.

CN=user1,OU=Security,OU=Groups,OU=Corp,DC=test,DC=company,DC=com;
CN=user2,OU=Security,OU=Groups,OU=Corp,DC=test,DC=company,DC=com;
var removeUsersList = current.variables.RemoveUserOrGroup;
    if(removeUsersList)
    {
        var b = JSON.parse(removeUsersList);
        var removeUserdns = "";
        for (var key1 in b)
        {
            if(b.hasOwnProperty(key1))
            {
                removeUserdns += b[key1].DistinguishedName + ";";
            }
        }

        removeUserdns.toString();
        removeUserdns.substring(0, removeUserdns.length - 1);
    //  removeUserdns.slice(0, -1);
    }
1

There are 1 answers

0
Nitesh On BEST ANSWER

You need to do this:

removeUserdns = removeUserdns.substring(0, removeUserdns.length - 1);

because string behave as immutable, substring method returns a new string which you need to assign to removeUserdns.