如何获取特定键的 JSON 对象值

How to get JSON object values for a Particular key

我正在使用 JQGRId 获取 JSON 对象格式的网格数据。

结果类似于:

{"Key":"value1"},{"Key":"value2", "id":"id"}

我需要将所有值放入数组中 "key"。

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"]