在Javascript / AngularJS中获取HashMap的Key和Value(get Key and Value of HashMap in Javascript/AngularJS)

编程入门 行业动态 更新时间:2024-10-23 02:10:04
在Javascript / AngularJS中获取HashMap的Key和Value(get Key and Value of HashMap in Javascript/AngularJS)

我在前端有这个HashMap从后端获取:

var myVar = {"24":{"amount":2,"minutes":30},"32":{"amount":3,"minutes":30}}

有谁知道我可以如何获得JavaScript / AngularJS中的键和值? 我努力了

{{myVar.24}} {{myVar.next()}}

但没有任何工作。

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.

最满意答案

这是javascript中的一个对象,在这里你使用数字字符串作为关键字,以便使用此语法访问对象值myVar [key] ; 看下面的例子

var myVar = {"24":{"amount":2,"minutes":30},"32":{"amount":3,"minutes":30}}
console.log(myVar['24']); 
  
 

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

更多推荐

本文发布于:2023-04-28 04:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1329796.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:AngularJS   Javascript   Key   HashMap

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!