Yet another PHP function port to JS, directly added to the String prototype.

String.prototype.rtrim = function(toTrim) {
    var s = this,
        e = s.length - 1;

    if (toTrim == null) {
        return s.trimRight();
    } else if (toTrim instanceof Array) {
        toTrim = toTrim.join();
    }

    while ((e >= 0) && (toTrim.indexOf(s.charAt(e)) != -1)) {
        s = s.substr(0, e);
        e--;
    }

    return s;
};

// Use it
myString = myString.rtrim(); // removes spaces (calls myString.trimRight())
myString = myString.rtrim(['.', ',']); // removes periods and commas
myString = myString.rtrim(['.,']); // same here