How to get JSON object values for a Particular key

北城余情 提交于 2019-12-25 18:39:11

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!