Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Say what the thing is
  2. interface MyThingy {
  3.   name: string,
  4.   age: number,
  5.   address: string,
  6.   [key: string]: string|number
  7. }
  8. // Include that when declaring the variable
  9. var datasource: MyThingy[] = [
  10.   { name: 'x', age: 20, address: 'yyyy' },
  11.   { name: 's', age: 30, address: 'zzzz' }
  12. ];
  13.  
  14. let keys: Object[] = Object.keys(datasource[0]);
  15. let dlen: number = datasource.length as number;
  16. while (dlen--) {
  17.     let kLn: number = keys.length;
  18.     while (kLn--) {
  19.         let key: string = keys[kLn] as string;
  20.         let mkey: string | number; // Since age is number, the other two are strings
  21.         if (key == "age") {
  22.             mkey = datasource[dlen][key] as number;  
  23.         } else {
  24.             mkey = datasource[dlen][key] as string;  
  25.         }
  26.        
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement