Write object to array in function - Javascript Array Operation

Javascript examples for Array Operation:Array of Object

Description

Write object to array in function

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(){//  ww w.  j ava  2 s. com
var obj = {
  name : 'Tim',
  age : 20,
  hasPets : false
};

console.log(arrayToObject(obj));
function arrayToObject(obj) {
  var result =  Object.keys(obj).map(function(item){
    return obj[item];
  });
  return result;
};

    }

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

Related Tutorials