有像python这样的javascript中的字典吗? [英] are there dictionaries in javascript like python?
本文介绍了有像python这样的javascript中的字典吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在这样的javascript中创建一个字典
i need to make a dictionary in javascript like this
我不记得确切的符号,但它是这样的:
i dont remember the exact notation, but it was something like:
states_dictionary={ CT=[alex,harry], AK=[liza,alex], TX=[fred, harry] ........ }
javascript中有这样的东西吗?
is there such a thing in javascript?
推荐答案
这是一篇旧文章,但我认为无论如何我应该提供一个图解答案。
This is an old post, but I thought I should provide an illustrated answer anyway.
使用JavaScript的对象表示法。像这样:
Use JavaScript's object notation. Like so:
states_dictionary={
"CT":["alex","harry"],
"AK":["liza","alex"],
"TX":["fred", "harry"]
};
并且要访问这些值:
states_dictionary.AK[0] //which is liza
或者您可以使用JavaScript文字对象表示法,其中键不需要在引号中:
or you can use JavaScript literal object notation, whereby the keys not require to be in quotes:
states_dictionary={
CT:["alex","harry"],
AK:["liza","alex"],
TX:["fred", "harry"]
};
这篇关于有像python这样的javascript中的字典吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文