keys of json object javascript code example

Example 1: get all keys in json object

var obj = {name: "Jeeva", age: "22", gender: "Male"}
console.log(Object.keys(obj))

Example 2: js object keys

var myObj = {no:'u',my:'sql'}
var keys = Object.keys(myObj);//returnes the array ['no','my'];

Example 3: js get json keys

myObject = {
	"key": "value"
}

Object.keys(myObject); // get array of keys

Example 4: key value json javascript

var jsonArray = '{"required":1, "minlength":2}'
var jsonParsedArray = JSON.parse(jsonArray);
for (key in jsonParsedArray) {
  if (jsonParsedArray.hasOwnProperty(key)) {
      console.log("%c "+key + " = " + jsonParsedArray[key],"color:cyan");
  }
}

Example 5: javascript get json keys

Object.keys(jsonData).forEach(function(key) {
    var value = jsonData[key];
    // ...
});