Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Say what the thing is
- interface MyThingy {
- name: string,
- age: number,
- address: string,
- [key: string]: string|number
- }
- // Include that when declaring the variable
- var datasource: MyThingy[] = [
- { name: 'x', age: 20, address: 'yyyy' },
- { name: 's', age: 30, address: 'zzzz' }
- ];
- let keys: Object[] = Object.keys(datasource[0]);
- let dlen: number = datasource.length as number;
- while (dlen--) {
- let kLn: number = keys.length;
- while (kLn--) {
- let key: string = keys[kLn] as string;
- let mkey: string | number; // Since age is number, the other two are strings
- if (key == "age") {
- mkey = datasource[dlen][key] as number;
- } else {
- mkey = datasource[dlen][key] as string;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement