How to access the first property of an object in Node.js

1 Answer

0 votes
const obj = {
  'lang-1': 'node.js',
  '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
node.js

*/

 



answered Jul 11, 2022 by avibootz

Related questions

1 answer 137 views
1 answer 129 views
1 answer 138 views
1 answer 138 views
1 answer 138 views
1 answer 128 views
1 answer 134 views
...