Looking for assistance with parsing a JSON file (test.json) and removing duplicate "name" entries from the test array.
{
"test": [{
"name": "jeb",
"occupation": "teacher"
},
{
"name": "jeb",
"occupation": "writer"
},
{
"name": "bob",
"occupation": "skydiver"
}
]
}
Here is the code I have so far:
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var myObj = JSON.parse(this.responseText);
var i;
var test= myObj.test.length;
for (i=0; i<=myObj.test.length; i++) {
var name = myObj.test[i].name;
var occupation = myObj.test[i].occupation;
console.log(name + " and " + occupation)
}
}
}
xmlhttp.open("GET", "test.json", true);
xmlhttp.send();
The current output is:
jeb and teacher
jeb and writer
bob and skydiver
Desired output:
jeb and teacher, writer
bob and skydiver
Any help or suggestions would be greatly appreciated. Thank you!