Given the following:
var person = {name: "", address: "", phonenumber: ""}
I am trying to implement a loop to gather user input (until they choose to stop inputting information by entering nothing or clicking cancel). My goal is to utilize the person object as a prototype.
The objective is to create an object that can store the name, address, and phone number of multiple individuals. My approach involves dynamically adding an array to an object in each iteration of the loop. Here is a snippet of my code:
var person = {name: "", address: "", phonenumber: ""}
var customer = []; //used to store each person
var input = "x";
//loop prompting user to input name/address/phone number
for(var i = 0; input != ""; i++){
var input = prompt("Input separated by commas");
//example input: mike, main, 123456789
var results = input.split(", "); //create an array from the input
//move input into the person array.
//person to look like {name = "mike", address = "main", phone = "123456789"}
person.name = results.shift();
person.address = results.shift();
person.phone = results;
customer[i] = person;//store the person array into the customer array.
}
I've been attempting to dynamically generate and access something like this:
customer =
[{name, address, phone},
{name, address, phone},
{name, address, phone}]
However, I am encountering errors when trying to access and print the data. When I use
console.log(customer[0].phone);
it seems like there is nothing stored in customer[0].phone and it does not produce an output.
Upon further investigation, I discovered that I cannot access the data I collected from user inputs. When attempting to print or display the customer array, I receive messages like [object Object] without the actual data.