Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Convert string to camel case

function toCamelCase(str){

   let strArray;
   

   if(str === ''){
       return ''
   }
   

   if(str.indexOf('-') !== -1){
       strArray = str.split('-')
   }else{
       strArray = str.split('_')
   }


   let capitalString = strArray[0]

   for(let i=1; i<strArray.length;i++){
       capitalString+= capitalize(strArray[i])
   }
   
   return capitalString
 
 }
 let capitalize = (str) =>{
    return str[0].toUpperCase()+str.slice(1)
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Convert #string #camel #case
ADD COMMENT
Topic
Name
7+2 =