使用Javascript:添加到一个关联数组 [英] Javascript: Adding to an associative array
本文介绍了使用Javascript:添加到一个关联数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个函数调用插入它有两个参数(名称,telnumber)。
当我把这个功能我想添加到一个关联数组。
因此,例如,当我做到以下几点:
插入(约翰福音,999);
插入(亚当,5433);
我想它,以便存储这样的:
[0]
{
名字:约翰,数:999
}
[1]
{
名称:亚当,编号:5433
}
解决方案
这样的事情应该做的伎俩:
VAR ARR = [];
功能插件(姓名,号码){
arr.push({
名称:姓名,
号码:号码
});
}
I have a function called insert which takes two parameters (name, telnumber).
When I call this function I want to add to an associative array.
So for example, when I do the following:
insert("John", "999");
insert("Adam", "5433");
I want to it so be stored like this:
[0]
{
name: John, number: 999
}
[1]
{
name: Adam, number: 5433
}
解决方案
Something like this should do the trick:
var arr = [];
function insert(name, number) {
arr.push({
name: name,
number: number
});
}
这篇关于使用Javascript:添加到一个关联数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文