Monday, August 14, 2017

Name of property of an object

Use Object.keys to get an array of the properties on an object.

Example:

JAVA SCRIPT:

var StdDetails = {
    StdName: "Mohit",
    StdClass: "MCA"
  };
console.log(Object.keys(StdDetails)); 
console.log("Property Names : " + Object.keys(StdDetails)); 
console.log("Value of 0 index(StdName) property : " + StdDetails[Object.keys(StdDetails)[0]]);


OUTPUT:

  1. ["StdName""StdClass"]
    1. 0:"StdName"
    2. 1: "StdClass"
    3. length:2
Property Names : StdName,StdClass

Value of 0 index(StdName) property : Mohit

No comments:

Post a Comment