RE: Loop on array of objects |
There are a few ways to iterate over an array.
var result = Http.requestJSON("http://endospore.xxxx.com:85/api/Data/GetPersons");
var text = "Persons are: ";
for (i = 0; i < result.length(); i++) {
var person = result[i].Name + " " + result[i].Surname;
text = text + person + "<br>";
}
You can also use,
var result = Http.requestJSON("http://endospore.xxxx.com:85/api/Data/GetPersons");
var text = "Persons are: ";
for (person in result) {
text = text + person.Name + " " + person.Surname + "<br>";
}
Or to iterate over an array's elements, or any attribute set of an object use,
var result = Http.requestJSON("http://endospore.xxxx.com:85/api/Data/GetPersons");
var text = "Persons are: ";
for (person in result.element) {
text = text + person.Name + " " + person.Surname + "<br>";
}
|
|
|
|
|