Q:

Get JSON key from object - AngularJS

I have a JSON object that contains a map of values. The keys of these map item are predefined. I use ng-repeat to create a button for each map item and I pass the item to the method via ng-click.
To execute a certain call, I now need the key of the item. How can I get the key of the given item?
The JSON looks like
"map": {
    "0": {
      "id": 1,
      "value": "123",
    },
    "1": {
      "id": 5,
      "value": "567",
    }
}

.html
<div ng-repeat="item in object.map">
    <button ng-click="load(item)" type="button">A</button>
</div>

app.js
$scope.load= function(item) {
    // HOW TO GET THE KEY OF THE GIVEN MAP ITEM
};

A:

You can iterate over the properties of this object, getting the pair (key, item), using the following syntax:
<div ng-repeat="(key, item) in object.map">
    <button ng-click="load(key, item)" type="button">A</button>
</div>

In this way, you pass the key of the item to the load function. In this link, you can find more details about this syntax for ng-repeat.

