gpt4 book ai didi

javascript - Json数据中某个字段的最大数字

转载 作者:行者123 更新时间:2023-11-28 12:18:31 25 4
gpt4 key购买 nike

我的Json数据如下

[{
"Name": "PieChart",
"Id": "1",
"ColumnLocation": "0",
"RowLocation": "0"
}, {
"Name": "Calendar",
"Id": "2",
"ColumnLocation": "1",
"RowLocation": "0"
}, {
"Name": "FavouriteFilter",
"Id": "3",
"ColumnLocation": "2",
"RowLocation": "0"
}, {
"Name": "FilterResults",
"Id": "4",
"ColumnLocation": "0",
"RowLocation": "1"
}, {
"Name": "Watched",
"Id": "5",
"ColumnLocation": "1",
"RowLocation": "1"
}]

我需要找到上述数据的ColumnLocation的最大编号。我需要这些信息,因为我可以根据此列数绘制仪表板。

最佳答案

减少:

const a = [{
"Name": "PieChart",
"Id": "1",
"ColumnLocation": "0",
"RowLocation": "0"
}, {
"Name": "Calendar",
"Id": "2",
"ColumnLocation": "1",
"RowLocation": "0"
}, {
"Name": "FavouriteFilter",
"Id": "3",
"ColumnLocation": "2",
"RowLocation": "0"
}, {
"Name": "FilterResults",
"Id": "4",
"ColumnLocation": "0",
"RowLocation": "1"
}, {
"Name": "Watched",
"Id": "5",
"ColumnLocation": "1",
"RowLocation": "1"
}];

const r = a.reduce((a, c) => (c.ColumnLocation > a) ? c.ColumnLocation : a, 0);

console.log(r)

关于javascript - Json数据中某个字段的最大数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43767940/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com