Below is a code snippet that retrieves and organizes a list of values from JSON data in alphanumeric order based on a specific key-value pair:
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var myObjjj = JSON.parse(this.responseText);
var result = myObjjj.features.filter(c => c.properties.AREAID === "area4").map(res => res.properties.CDNAME + "<br>").sort().join('');
document.getElementById("list").innerHTML = result;
}
};
xmlhttp.open("GET", "https://api.npoint.io/eed1932ca3c208946d86", true);
xmlhttp.send();
<html>
<head>
<title>Read data from External JSON file using JavaScript</title>
</head>
<body>
<h3>
Data extracted from External JSON file using JavaScript.
</h3>
<p id="list" style="border: 2px solid yellow;"></p>
</body>
</html>
The JSON data retrieved from the specified URL contains information about different divisions and areas. The objective is to eliminate duplicate values to display only distinct entries, as shown below:
Area No. 13
Center No. 14
Division No. 11
Division No. 13
Division No. 14
Division No. 16
Division No. 17
Division No. 18
Division No. 19