How to loop through an object in reverse order with TypeScript

1 Answer

0 votes
let obj = {
  id: 94801287,
  name: "Albus Dumbledore",
  academicrank: "Professor"
};

const reversedKeys = Object.keys(obj).reverse();

console.log(reversedKeys); 

reversedKeys.forEach(key => {
  	console.log(key, obj[key]); 
});

  
  
  
/*
run:
  
["academicrank", "name", "id"] 
"academicrank",  "Professor" 
"name",  "Albus Dumbledore" 
"id",  94801287 
  
*/

 



answered May 17, 2022 by avibootz

Related questions

1 answer 119 views
1 answer 125 views
4 answers 123 views
2 answers 141 views
2 answers 134 views
1 answer 94 views
...