JavaScript - Object property for creating contact list

1:  var friends = new Object();  
2:  friends.steve = {  
3:    firstName : 'Steve',  
4:    lastName : 'Shock',  
5:    number : 13533334444,  
6:    address : ['20','Rahoon']  
7:  };  
8:  friends.bill = {  
9:    firstName : 'Bill',  
10:    lastName : 'Guangyuan',  
11:    number : 13514437556,  
12:    address : ['26','Angues House']  
13:  };  
14:  function list(friends){  
15:    for (var p in friends) {  
16:      console.log(p);    
17:    }  
18:  };  
19:  var search = function (name){  
20:    for(var p in friends){  
21:      console.log(friends[p].firstName);  
22:      if(friends[p].firstName === name){  
23:        console.log(p);  
24:        return friends[p];  
25:      }  
26:    }    
27:  };  
28:  list(friends);  
29:  search('Steve');  

No comments:

Post a Comment