The data I've got is an array of objects
[Object1,
Object2,
Object3,
...
]
Each Object is an json format
{"key1":"value1","key2":"value2","key3":"value3","key4":"value4"...}
To get all the value of a few given key
function getFields(input, field) {
var output = [];
for (var i=0; i < input.length ; ++i){
output.push(input[i][field]);
}
return output; //loop through all the objects and find all the values for one key
}
$('.destination .list-group-item').each(function(){
chosen_field.push($(this).text());
});
var json_join = new Array();
for (var i = 0; i < chosen_field.length; i++) {
var result = (getFields(data,chosen_field[i]));
var json = new Object();
json.key = chosen_field[i];
json.value = JSON.stringify(result);
json_join.push(json);
}
//loop through all the selected fields and return each value array and combine to a new json file
preparing for sending to php in the format of json file.
The data I've got is an array of objects [Object1, Object2, Object3, ... ] Each Object is an json format {"key1":"value1","key2":"value2","key3":"value3","key4":"value4"...} To get all the value of a few given key