Advertisement
Guest User

Wyświetlanie danych z obiektu

a guest
Apr 27th, 2017
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function isObject(value) {
  2.     return typeof value === "object" && value.constructor === Object;
  3. }
  4.  
  5. function displayData(obj) {
  6.  
  7.     for(var key in obj) {
  8.         if( isObject(obj[key]) ) {
  9.             console.log(key + ":");
  10.             displayData(obj[key]);
  11.             continue;
  12.         }
  13.         console.log(key + ": " + obj[key]);
  14.     }
  15.  
  16. }
  17.  
  18. var person = {
  19.     "imię": "Grzegorz",
  20.     "nazwisko": "Sumara",
  21.     "wiek": 30,
  22.     "język programowania": {
  23.         "html": "HTML",
  24.         "css": "CSS",
  25.         "JavaScript": "JavaScript",
  26.         "jQuery": "jQuery",
  27.         "Angular": {
  28.             "Old Version": 1,
  29.             "New Version": 2
  30.         }
  31.     }
  32. };
  33.  
  34. displayData(person);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement