问题
I am using JQGRId to get the grid data in JSON object format.
Result is something like :
{"Key":"value1"},{"Key":"value2", "id":"id"}
I need to get all the values into an array for "key".
回答1:
var arr = [{"Key":"value1"},{"Key":"value2", "id":"id"}];
var anArrayOfKeyValues = [];
arr.forEach(function(ob, i) {
if("Key" in ob) anArrayOfKeyValues.push(ob.Key);
});
console.log(anArrayOfKeyValues); // ["value1", "value2"]
来源:https://stackoverflow.com/questions/39113265/how-to-get-json-object-values-for-a-particular-key