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
Just re-initialise the object:
myObj = { p1: myObj.p1, p2: myObj.p2, p100: myObj.p100 };
Another way is to delete certain properties, which is less effective:
var prop = ['p1', 'p2', 'p100']; for (var k in myObj) { if (prop.indexOf(k) < 0) { delete myObj[k]; } }