Javascript d3.nest()键/值未定义的值

Javascript d3.nest()键/值未定义的值,javascript,d3.js,nested,key-value,Javascript,D3.js,Nested,Key Value,在嵌套数据之后,我试图从key/值中获取所有n个值的数组。我已经设法console.log所有n个值,但最终结果是一个未定义的数组[undefined,…,undefined] //Nesting data by category let updatedData = d3.nest() .key(d => d.category) .sortValues((a, b) => a.year - b.year) .e

在嵌套数据之后,我试图从key/值中获取所有n个值的数组。我已经设法
console.log
所有n个值,但最终结果是一个未定义的数组[undefined,…,undefined]

//Nesting data by category
let updatedData = d3.nest()
            .key(d => d.category)
            .sortValues((a, b) =>  a.year - b.year)
            .entries(data);
嵌套后的数据:

key: "clothing, beauty, & fashion"
values: Array(11)
0: {year: 2004, category: "clothing, beauty, & fashion", n: 141}
1: {year: 2005, category: "clothing, beauty, & fashion", n: 203}
2: {year: 2006, category: "clothing, beauty, & fashion", n: 195}
3: {year: 2007, category: "clothing, beauty, & fashion", n: 296}


key: "computers & internet"
values: Array(11)
0: {year: 2004, category: "computers & internet", n: 2489}
1: {year: 2005, category: "computers & internet", n: 2200}
2: {year: 2006, category: "computers & internet", n: 2114}
3: {year: 2007, category: "computers & internet", n: 2402}
现在获取所有n值:

const nValues = [].concat.apply([], updatedData.map(d => d.values[d.values.forEach(d => console.log(d.n))]));
console.log(nValues);

我做错了什么?

您只需映射到
键,并为每个分组数据返回
n

 const nValues = data.map(group => group.values.map(e=> e.n))
const数据=[
{
“关键”:“服装、美容和时尚”,
“价值观”:[
{
“年份”:2004年,
“类别”:“服装、美容和时尚”,
“n”:141
},
{
“年份”:2005年,
“类别”:“服装、美容和时尚”,
“n”:203
},
{
“年份”:2006年,
“类别”:“服装、美容和时尚”,
“n”:195
},
{
“年份”:2007年,
“类别”:“服装、美容和时尚”,
“n”:296
}
]
},
{
“密钥”:“计算机和互联网”,
“价值观”:[
{
“年份”:2004年,
“类别”:“计算机和互联网”,
“n”:2489
},
{
“年份”:2005年,
“类别”:“计算机和互联网”,
“n”:2200
},
{
“年份”:2006年,
“类别”:“计算机和互联网”,
“n”:2114
},
{
“年份”:2007年,
“类别”:“计算机和互联网”,
“n”:2402
}
]
}
]
const nValues=data.map(group=>group.values.map(e=>e.n))
console.log(n值)