Add function to Add Contacts: How to be "general"?


#1

Hello,
I have been doing this session, and occurs me: in the Add function, I used:

" var add = function (firstName,lastName,phoneNumber,email){
var person = new Object();
person.firstName = firstName;
person.lastName = lastName;
person.phoneNumber = phoneNumber;
person.email = email;
contacts[contacts.length] = person;
}; "

But, for me, it is NOT ok.

The contacts is a array with bob and mary: var contacts = [bob, mary];
So, every time I use Add function, to me, I am doing this: [bob, mary, person]. Then [bob, mary, person, person]. And so on.

How do I have granted I am adding a legit new var every time? I am a bit confusing.

thank you


#2

var add = function(firstName, lastName, phoneNumber, email){

contacts[contacts.length] = {
    firstName: firstName,
    lastName: lastName,
    phoneNumber: phoneNumber,
    email: email
};

};