Convert object camelCase keys to underscore_case - Javascript String Operation

Javascript examples for String Operation:String Case

Description

Convert object camelCase keys to underscore_case

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//from  w  ww  . j av  a 2 s  .co  m
function camelToUnderscore(key) {
    var result = key.replace( /([A-Z])/g, " $1" );
    return result.split(' ').join('_').toLowerCase();
}
console.log(camelToUnderscore('helloWorldWhatsUp'));
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials