leodutra
5/14/2012 - 7:10 PM

Camelize a String Replacing Spaces and Underscores (JavaScript)

Camelize a String Replacing Spaces and Underscores (JavaScript)

function camelize(string)
{
    var words = (string || '').split(/[_\s-]/gim);
    var length = words.length;
    for (var i = 1; i < length; ++i)
    {
        words[i] = words[i].charAt(0).toUpperCase() + words[i].substr(1);
    }
    return words.join('');
}