Computer Science, asked by rakshithkumar4010, 11 months ago

How to convert uppercase to camelcase in javascript?

Answers

Answered by Anonymous
0
HEY DEAR ...


function camelize(str) { return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(letter, index) { return index == 0 ? letter.toLowerCase() : letter.toUpperCase(); }).replace(/\s+/g, ''); } camelize("EquipmentClass name"); camelize("Equipment className"); camelize("equipment class name"); camelize("Equipment Class Name"); // all output "equipmentClassName



Edit: Or in with a single replace call, capturing the white spaces also in the RegExp.

function camelize(str) { return str.replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, function(match, index) { if (+match === 0) return ""; // or if (/\s+/.test(match)) for white spaces return index == 0 ? match.toLowerCase() : match.toUpperCase(); }); }

HOPE , IT HELPS ...
Similar questions