“Dapatkan nilai dari objek JSON di JavaScript” Kode Jawaban

nilai kunci 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");
  }
}
Indian Gooner

Dapatkan nilai dari objek JSON di JavaScript

var data = `{
  "employee": {
    "name": "John",
    "age": 30,
    "salary": 5000,
    "city": "New York",
    "skills": ["JavaScript", "CSS", "HTML"]
  }
}`;
// current data type is string 'data'
console.log(typeof data);

// convert data into JSON object
var parsedData = JSON.parse(data);
console.log(typeof parsedData);

// get value from JSON object in JavaScript
console.log(parsedData.employee.name,
            parsedData.employee.age,
            parsedData.employee.skills);
Clumsy Caiman

JavaScript Temukan Nilai JSON

function getCountryByCode(code) {
  return data.filter(
      function(data){ return data.code == code }
  );
}

var found = getCountryByCode('DZ');
Inexpensive Ibex

Jawaban yang mirip dengan “Dapatkan nilai dari objek JSON di JavaScript”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya