Sunday, April 19, 2015

Covert string to camel case using javascript

It is very easy to do using css


.className 
{
  text-transform:capitalize;
}

But sometimes we have to take care this by using javascript .There are many ways to accomplish this , see the example below


var myLabel = "sample text example"

var split = myLabel.split(' ');

//iterate through each of the "words" and capitalize them
for (var i = 0, len = split.length; i < len; i++) {
 split[i] = split[i].charAt(0).toUpperCase() + split[i].slice(1);
}

myLabel= split.join(' ');

//your result
console.log(myLabel); //Sample Text Example


Related Posts

1. How to remove duplicate from an array and get count of duplicated .

2. Save Google map as binary image

3. Top 10 professional bloggers in India - 2014

4. Auto complete using html5

5. Dynamic height for side bar


No comments :

Post a Comment