I have an object. I would like to modify the object (not clone it) by removing all properties except for certain specific properties. For instance, if I started with this o
var myObj = {a: 1, b: 2, c:3}; function keepProps(obj, keep) { for (var prop in obj) { if (keep.indexOf( prop ) == -1) { delete obj[prop]; } } } keepProps(myObj, ['a', 'b']); console.log(myObj);
http://jsfiddle.net/mendesjuan/d8Sp3/2/