Bubbs

array/loop practice

Jan 7th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let arr = [
  2.     {
  3.         PERSON: {
  4.             name: "Barry Johnson",
  5.             age: 17,
  6.             fav_color: "Green",
  7.             list_of_hobbies: {
  8.                 hobby_1: "Music Production",
  9.                 hobby_2: "Video Production",
  10.                 hobby_3: "Shitposting" //dont judge Barry
  11.             },  
  12.         },
  13.     }
  14. ];
  15.  
  16. // will not work???
  17. function console_print(arr){
  18.     for(let i = 0; i < arr.length; i++){
  19.        for(hobby in arr[i].list_of_hobbies){
  20.             console.log(arr[i].list_of_hobbies[hobby]);
  21.        }
  22.     }
  23. }
  24.  
  25. //will work???
  26. function print_obj(arr){
  27.     for(let i = 0; i < arr.length; i++){
  28.         if(i % 2 == 0){
  29.             console.log(arr[i]);
  30.         }
  31.     }
  32. }
  33.  
  34. print_obj(arr);
  35. console_print(arr);
  36.  
  37. //theres no html doc or anything its just linked to a blank html doc so I can use the console
Add Comment
Please, Sign In to add comment