code:
var json = {
"test": [
{
"a": "val_a1",
"b": "val_b1",
"c": "val_c1",
"d": "val_d1"
},
{
"a": "val_a2",
"b": "val_b2",
"c": "val_c2",
"d": "val_d2"
},
{
"a": "val_a3",
"b": "val_b3",
"c": "val_c3",
"d": "val_d3"
}
]
};
var new_json = {test:{}};
$(document).ready(function(){
$.each(json.test, function(key, value){
//console.log("key = "+key);
//console.log("value = ");
//console.log(value);
var new_obj = {};
new_obj.a = value.a;
new_obj.c = value.c;
new_json.test[key] = new_obj;
});
console.log("new_json = ");
console.log(new_json);//here new_json will only contain attributes "a" and "c" only
});
solved Create a new javascript object with only selected attributes from another existing object