Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  8] [ 6]  / answers: 1 / hits: 57757  / 13 Years ago, wed, november 30, 2011, 12:00:00

I have a function called insert which takes two parameters (name and 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
}

More From » arrays

 Answers
15

Something like this should do the trick:



var arr = [];
function insert(name, number) {
arr.push({
name: name,
number: number
});
}

[#88824] Tuesday, November 29, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
yaquelina

Total Points: 517
Total Questions: 101
Total Answers: 96

Location: Egypt
Member since Tue, Jul 6, 2021
3 Years ago
yaquelina questions
;