<!DOCTYPE html>
<html>
<body>
<h2>Parse Json Array Object JavaScript</h2>
<p>
First Name: <span id="fname"></span><br>
Last Name: <span id="lname"></span><br>
</p>
<script>
var getEmployee =
'{"employees":[' +
'{"firstName":"Sachin","lastName":"Roy" },' +
'{"firstName":"Sourabh","lastName":"Joshi" },' +
'{"firstName":"Rohit","lastName":"Sharma" }]}';
//var jsonData = eval ("(" + txt + ")");
var jsonData = JSON.parse(getEmployee);
for (var i = 0; i < jsonData.employees.length; i++) {
var counter = jsonData.employees[i];
//console.log(counter.counter_name);
alert(counter.firstName);
}
</script>
</body>
</html>
How to how to parse JSON array using JavaScript Code
Working Code Asked question July 6, 2023