How to access the first property of an object in TypeScript

1 Answer

0 votes
const obj = {
  'lang-1': 'typescript',
  'lang-2': 'c',
  'lang-3': 'python',
};

const firstKey = Object.keys(obj)[0]; 
console.log(firstKey);

const firstValue = Object.values(obj)[0]; 
console.log(firstValue);
  
  
  
  
/*
run:
  
"lang-1"
"typescript" 
  
*/

 



answered Jul 11, 2022 by avibootz

Related questions

1 answer 157 views
1 answer 137 views
1 answer 153 views
1 answer 158 views
1 answer 156 views
1 answer 154 views
...