Creating A Contact List

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

Lecture 258:- Creating A Contact List

To create a contact list in JavaScript, we can use an array to store the contact objects. Each contact object can have properties such as name, email, phone number, etc.

Here is an example of how we can create a contact list:

javascriptCopy code

// Create an empty array to store the contacts let contacts = []; // Function to add a new contact function addContact(name, email, phone) {  // Create a new contact object  let contact = {    name: name,    email: email,    phone: phone  };  // Add the contact to the array  contacts.push(contact); } // Function to display all contacts function displayContacts() {  // Loop through the contacts array and display each contact  for (let i = 0; i < contacts.length; i++) {    console.log("Name: " + contacts[i].name);    console.log("Email: " + contacts[i].email);    console.log("Phone: " + contacts[i].phone);    console.log("--------------------------");  } } // Add some contacts addContact("John Doe", "[email protected]", "555-555-5555"); addContact("Jane Doe", "[email protected]", "555-123-4567"); addContact("Bob Smith", "[email protected]", "555-987-6543"); // Display all contacts displayContacts();

In this example, we have created an empty array called contacts to store the contact objects. We have also created two functions, addContact and displayContacts.

The addContact function takes three parameters, name, email, and phone, and creates a new contact object with these properties. The function then adds the contact object to the contacts array using the push method.

The displayContacts function loops through the contacts array using a for loop and displays each contact object's properties.

We have also added some contacts using the addContact function and displayed all the contacts using the displayContacts function.

This is just an example, and in a real application, we might want to use a database to store the contact information or use some libraries to manage the contact list.

30. My First Express App - Continued

Comments: 2

profile
@niteshguptav63
17-Nov-2024, 01:39 PM

I am not able to access videos from second class and further. I have already completed first class

profile
@niteshguptav63
16-Nov-2024, 10:56 AM

When will I get my course?

profile
@admin79
17-Nov-2024, 01:29 PM

Now, Your query was resolved.

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?