Jquery map convert list of dashed properties into object - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:map

Description

Jquery map convert list of dashed properties into object

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.7.1.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){/*from   www.  jav  a  2 s  .  c  om*/
var classname = "username_admin color_red a_2 e_5";
var res = {};
$.map(classname.split(' '),function(el, i) {
    var tmp = el.split('_');
    res[tmp[0]] = tmp[1];
    return res;
});
console.log(res);
    });

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

Related Tutorials