Javascript String camelCase=function()

Description

Javascript String camelCase=function()


String.prototype.camelCase=function(){
  if (this.length === 0) {
    return '';
  }/* w  w  w.ja va 2  s  .  c o m*/
  return this.trim().split(' ').map((e)=>{
    return e[0].toUpperCase() + e.substring(1,e.length);
  }).join('')
}

Javascript String camelCase=function()

String.prototype.camelCase=function(){
  return this.replace(/(^| )(\w)/g, s => s.toUpperCase()).split(' ').join('')
}

Javascript String camelCase=function()

/*/*from www  . j a  v a2 s .  co m*/
Description:

Write simple .camelcase method (camel_case function in PHP) for strings. All words must have their first letter capitalized without spaces.

For instance:

"hello case".camelCase() => HelloCase
"camel case word".camelCase() => CamelCaseWord*/

String.prototype.camelCase=function(){
console.log(this);
   return this.length == 0 ? "" :this.trim()
                                 .split(" ")
                                   .map(a => a[0].toUpperCase()+a.substring(1,a.length))
                                    .join("");
}



PreviousNext

Related