Reputation: 5719
I have this HashMap in Frontend getting from Backend:
var myVar = {"24":{"amount":2,"minutes":30},"32":{"amount":3,"minutes":30}}
Does anyone know how I can get the keys and the values in Javascript/AngularJS? I have tried
{{myVar.24}}
{{myVar.next()}}
but nothing works.
Upvotes: 2
Views: 21021
Reputation: 4388
This is an object in javascript and here you use number string as a key so to access the object values use this syntax myVar[key] ; look at the example below
var myVar = {"24":{"amount":2,"minutes":30},"32":{"amount":3,"minutes":30}}
console.log(myVar['24']);
Upvotes: 2
Reputation: 50326
You can use Object.keys & Object.values
var myVar = {
"24": {
"amount": 2,
"minutes": 30
},
"32": {
"amount": 3,
"minutes": 30
}
}
var getKeysArray = Object.keys(myVar);
var getValueArray = Object.values(myVar)
console.log(getKeysArray, getValueArray)
Upvotes: 3