且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

想要使用Javascript将一个JSON对象拆分为多个JSON对象

更新时间:2023-01-08 12:11:18

您可以创建一个返回所需数组的函数:
然后,您可以映射并在JSON中的属性上调用它:

You could make a function that returns the array you want: You could then map through and call this on the properties in your JSON:

function makeArray(value) {
  return j.map(function(a) {
    return {[value]: a[value]};
  });
}

var labels = makeArray('label');

工作示例