I have this simple JSON file that supposed to be one array Paths with 3 arrays (Path1, Path2, Path3) of objects.
{
"Paths":
{
"Path1": [{"x":"4","y":"182"},{"x":"220","y":"186"}],
"Path2": [{"x":"4","y":"222"},{"x":"256","y":"217"}],
"Path3": [{"x":"6","y":"170"},{"x":"216","y":"183"}]
}
}
Considering an online example that I found I am doing this to get the length of Paths node:
// It's Phaser 3 (JS game framework)
// this.cache.json.get('data') -> returns me the JSON contents
var json = this.cache.json.get('data');
for (var pos in json.Paths) {
var len = parseInt(json.Paths[pos].length)+1;
console.log(len);
}
Although it works I would like to know if this is the correct approach because it seems to be too much code only to get a node length.
Thanks!