Advertisement
Militsa

15. Turn Object into JSON String

Dec 25th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. function solve(arr) {
  2. let obj = {};
  3.  
  4. for(line of arr) {
  5. let tokens = line.split(' -> ');
  6. obj[tokens[0]] = +tokens[1] ? +tokens[1] : tokens[1];
  7. }
  8.  
  9. console.log(JSON.stringify(obj));
  10. }
  11.  
  12. //solve(['name -> Angel','surname -> Georgiev', 'age -> 20', 'grade -> 6.00', 'date -> 23/05/1995', 'town -> Sofia']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement