Iteration vs Assignment

Edit on GitHub

Iteration vs direct assignment

Setup

var obj = {thing:5, a: 8, b: 4, c: 5, d:6, e:7, f:8, g:9, h:10};
var otherObj = {};

Tests

  • Iteration

    for(var key in obj) {
      otherObj[key] = obj[key];
    }
  • Assignment

    otherObj.thing = obj.thing;
    otherObj.a = obj.a;
    otherObj.b = obj.b;
    otherObj.c = obj.c;
    otherObj.d = obj.d;
    otherObj.e = obj.e;
    otherObj.f = obj.f;
    otherObj.g = obj.g;
    otherObj.h = obj.h;