Contact List // Help me understand


#1

Hello! I'm not sure I fully understand the functionality of this code. I'm confused most by the for/in loops. What are the list and search functions doing and how are they doing it? I need a logical explanation please. I cannot make sense of it.

friends = new Object();

friends.bill = new Object();
    friends.bill.firstName = "Bill"
    friends.bill.lastName = "Gates"
    friends.bill.number = "(555) 555-5555"
    friends.bill.address = ['1 Tech Way', 'Ozark', 'AL', '36360']
friends.steve = new Object();
    friends.steve.firstName = "Steve"
    friends.steve.lastName = "Jobs"
    friends.steve.number = "(555) 555-5555"
    friends.steve.address = ['1 Tech Way', 'Ozark', 'AL', '36360']
    
var list = function (friends) {
    for (var key in friends) {
        console.log(key)
    }
}

var search = function (name) {
    for (var key in friends) {
        if (friends[key].firstName === name) {
            console.log(friends[key]);
            return friends [key];
        }
    }
}


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.