Turn string into object attribute - Javascript Object

Javascript examples for Object:Reflection

Description

Turn string into object attribute

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <script>
var human = {/*www . ja v a2s. co m*/
  name: "Smith",
  age: "29"
};
var manAttributes = ["age","name"];
for(var prop in manAttributes){
  if(human.hasOwnProperty(manAttributes[prop])){
    console.log(manAttributes[prop] + ": "+human[manAttributes[prop]]);
  }
}

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

Related Tutorials