Upgrade auf unsere Diamond service und bauen wir Ihnen Ihre eigene app für Android oder iOS
Self, AIML, and scripting : Loop on array of objects

RE: Loop on array of objects

durch admin gepostet Mar 12 2018, 12:44

There are a few ways to iterate over an array.
In your code use result.length() not result.length

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>"; }


Id: 21313099
Gepostet: Mar 12 2018, 12:44
Aktualisiert: Mar 12 2018, 12:47
Antworten: 0
Ansichten: 427, heute: 1, Woche: 8, Monat: 8
Ich bin mir sicher, dass
Flag post als anstößig oder in Verletzung der Regeln dieser Website