I have successfully created a code snippet that retrieves JSON data and displays it in HTML using AngularJS.
<div class="activity" ng-app="stream" ng-controller="streamCtrl">
<ul ng-repeat="x in myData">
<p class="author"><a href="https://hypothes.is/stream?q=user:{{x.user}}">{{x.user}}</a></p>
<p class="context_title"><a class="context" href="{{x.links.incontext}}">{{x.document.title}}</a></p>
<p class="exact">{{x.target[0].selector.find(selector => selector.exact).exact}}</p>
<p class="text" btf-markdown="x.text">{{x.text}}</p>
<span ng-click="loadFromMenu($parent.$index)" ng-repeat="y in x.tags">
<a href="https://hypothes.is/stream?q=tag:{{y}}">[{{y}}]</a>
</span>
<p class="reply"><a href="{{x.links.incontext}}">reply</a></p>
<br>
</ul>
While everything is functioning correctly, I've noticed that the location of the key "exact" within the "selector" array can vary. Some API responses place it in the third subarray, while others place it in the fourth.
For example, in this specific JSON segment, "exact" is located in the third subarray within the selector:
{
"total": 9,
"rows":
[
{
"updated": "2016-07-19T20:46:47.509685+00:00",
"group": "__world__",
"target":
[
{
"source": "http://...",
"selector":
[
{
"endContainer": "/div[3]/div[1]/div[1]/section[1]/div[1]/p[98]",
"startContainer": "/div[3]/div[1]/div[1]/section[1]/div[1]/p[97]/b[1]",
"type": "RangeSelector",
"startOffset": 0,
"endOffset": 0
},
{
"type": "TextPositionSelector",
"end": 22803,
"start": 22676
},
{
"exact": "Are ...",
"prefix": "esearch...",
"type": "TextQuoteSelector",
"suffix": "List of References Berkeley,"
}
]
}
],
"links":
{
"json": "https://..",
"html": "https://..",
"incontext": "https://.."
},
"tags":
[
"a",
"b"
],
"text": "They ..",
...
]}
My concern is ensuring that Angular always accesses the "exact" property regardless of its position within the "selector" arrays. What would be the most effective approach to achieve this?