Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Convert string to camel case

//codewars:Convert string to camel case
function toCamelCase(str){
  //console.log(str, 'testing')
  if(str === ''){
    return ''
  } else {

   let containmentArea = []
   let splitString = str.replace(/[^A-Z0-9]/ig, "_").split("_")
   //[ 'the', 'stealth', 'warrior' ]
   let firstElement = containmentArea.push( splitString.splice(0,1) )

   for(let word in splitString){

     let splitWords = splitString[word].split('')
     let capitalLetter = splitWords[0].toUpperCase()

     splitWords.splice(0,1, capitalLetter)
     let joinedWord = splitWords.join('')

     containmentArea.push(joinedWord)
     let newSentence = containmentArea.join('')

   }
     return containmentArea.join('')
  }
}
Comment

Convert string to camel case

def to_camel_case(text):
    if text == '':
        return text
    for i in text:
        if i == '-' or i == '_':
            text = text.replace(text[text.index(i):text.index(i)+2], text[text.index(i)+1].upper(), 1)
    return text
Comment

how to convert string to camel case in javascript

const camelCase = (string) => {
  function camelize(str) {
    return str
      .replace(/(?:^w|[A-Z]|w)/g, function(word, index) {
        return index === 0 ? word.toLowerCase() : word.toUpperCase();
      })
      .replace(/s+/g, "");
  }
  const newText = camelize(string);
  return newText
};
Comment

convert string to camelCase

const camalize = function camalize(str) {
    return str.toLowerCase().replace(/[^a-zA-Z0-9]+(.)/g, (m, chr) => chr.toUpperCase());
}
Comment

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)
}
Comment

convert a camel case to string

convert camel case to string
Comment

PREVIOUS NEXT
Code Example
Javascript :: dynamic loop variable .each create hash javascript 
Javascript :: javascript close window on button click 
Javascript :: add query parameter to url react router v6 
Javascript :: axios error 
Javascript :: JavaScript count list items 
Javascript :: nodejs user input 
Javascript :: is a letter javascript 
Javascript :: count array filter javascript 
Javascript :: javascript canvas to image 
Javascript :: js split array into smaller arrays 
Javascript :: Attach token with http request angular 
Javascript :: promise.all async await 
Javascript :: how to set a string 
Javascript :: angularjs round to 2 decimal places input 
Javascript :: res.locals in express 
Javascript :: javascript response redirect 
Javascript :: push array javascript 
Javascript :: js trim all spaces 
Javascript :: how to replace strings with react components 
Javascript :: uploading file with fetch in js 
Javascript :: data-id html javascript 
Javascript :: sum all numbers in a range javascript 
Javascript :: updateone mongoose example 
Javascript :: moment compare time 
Javascript :: set attribute using each jquery 
Javascript :: is javascript good 
Javascript :: how to search for a voice channel within a guild using discord.js 
Javascript :: function currying javascript 
Javascript :: keydown events 
Javascript :: Uncaught TypeError: .replace is not a function 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =