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

2 Comments

@niteshguptav63
niteshguptav63 Nov 17, 2024 at 1:39 PM

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

@niteshguptav63
niteshguptav63 Nov 16, 2024 at 10:56 AM

When will I get my course?

@admin79
admin79 Nov 17, 2024 at 1:29 PM

Now, Your query was resolved.

Frequently Asked Questions About Sciaku Courses & Services

Quick answers to common questions about our courses, quizzes, and learning platform

Didn't find what you're looking for?

help_center Contact Support