7. Line by Line



I don't understand this line of the code:
if(friends[key].firstName === name)
can someone explain it to me and how it works?

var friends = {};
friends.bill = {
    firstName: 'Bill',
    lastName: 'lib',
    number: '(123) 456-7890',
    address: ['123 four street','las vegas','NV']
friends.steve = {
    firstName: 'Steve',
    lastName: 'eve',
    number: '(555) 555-5555',
    address: ['555 five road','las vegas','NV']
var list = function(object){
    for(var key in object){

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


In summary, if the particular key in the friends object in which other new objects were created, has a key, firstName, set that === name. The name is that argument your function would later receive when called.

=== equates both the value and data type

Note that each new object has key and values. key: 'value'

I hope I helped though! :slight_smile:


add else{ return friends}


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