Militsa

13. Storing Objects

Dec 25th, 2017
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function storingObjects(arr) {
  2.     let array = [];
  3.     for(let string of arr) {
  4.         let tokens = string.split(" -> ");
  5.         let name = tokens[0];
  6.         let age = tokens[1];
  7.         let grade = tokens[2];
  8.  
  9.         array.push({
  10.             Name: name,
  11.             Age: age,
  12.             Grade: grade
  13.         });
  14.     }
  15.  
  16.     for(let student of array) {
  17.         for(let key of Object.keys(student)) {
  18.             console.log(`${key}: ${student[key]}`)
  19.         }
  20.     }
  21. }
  22.  
  23. //storingObjects(['Pesho -> 13 -> 6.00','Ivan -> 12 -> 5.57','Toni -> 13 -> 4.90']);
Add Comment
Please, Sign In to add comment