I'm trying to produce a dynamic variable name for an object so that I can easily find it & modify or delete it after it was created.
It involves a contact list program. (still on local test so far)
example code :
while (choice === 2)
{
console.log("Add contact");
var contact = Object.create(Contacts);
contact+name.initContacts(firstname,age,phone); (user input)
listContacts.push(contact+name);
etc.....
}
problem is, it is supposed to be a loop, as long as the user still wants to add more contacts & so on, all contacts will be created with contact object: contact.name; contact.age etc, so i won't be able to find a specific contact with my object name.
I want my object name "contact" to be dynamic & different for each specified contact name inside the list.
example :
contact+name.name = prompt("Enter contact name");
i'd like my object name to look like (contact+name).name = "something"; so if the prompt name is "John" variable should be :
contactJohn.name = "John"; contactJohn.age = "30";
So i can find it easily afterwards.
If i initialize a contact manually :
var listContacts = [];
var contact1 = Object.create(Contacts);
contact1.initContacts("Pittsburg", "Caroline");
var contact2 = Object.create(Contacts);
contact2.initContacts("Nelson", "David");
listContacts.push(contact1);
listContacts.push(contact2);
I've already tried eval() thing, haven't got that much luck so far.
i can easily search those objects by their name : contact1 & contact2.