最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

get Key and Value of HashMap in JavascriptAngularJS - Stack Overflow

programmeradmin0浏览0评论

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.

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.

Share Improve this question asked Dec 30, 2017 at 5:07 qumaquma 5,75326 gold badges87 silver badges159 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

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)

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']);

发布评论

评论列表(0)

  1. 暂无评论