Run details:
Mozilla/5.0 (X11; Linux x86_64; rv:132.0) Gecko/20100101 Firefox/132.0
Firefox 132
Linux
Desktop
5 months ago
Test name Executions per second
for-in 22.2 Ops/sec
Object.keys 21.9 Ops/sec
Object.values 22.6 Ops/sec
Script Preparation code:
AخA
 
var obj = {
  'a': {
    id: 'a',
    num: 1
  },
  'b': {
    id: 'b',
    num: 1
  },
  'c': {
    id: 'c',
    num: 1
  },
  'd': {
    id: 'd',
    num: 1
  },
  'e': {
    id: 'e',
    num: 1
  },
  'f': {
    id: 'f',
    num: 1
  },
  'g': {
    id: 'g',
    num: 1
  },
};
Tests:
  • for-in

     
    for (var i=10000; i > 0; i--) {
      var output = []
      for (var key in obj) {
          output.push(obj[key]); 
      }
      console.log(output)
    }
  • Object.keys

     
    for (var i=10000; i > 0; i--) {
      var output = Object.keys(obj).map(key => obj[key]);
      console.log(output)
    }
  • Object.values

     
    for (var i=10000; i > 0; i--) {
      var output = Object.values(obj);
      console.log(output)
    }