我正在寻找一种非常快速,干净和有效的方法来获取以下JSON切片中的最大"y"值:
[
{
"x": "8/11/2009",
"y": 0.026572007
},
{
"x": "8/12/2009",
"y": 0.025057454
},
{
"x": "8/13/2009",
"y": 0.024530916
},
{
"x": "8/14/2009",
"y": 0.031004457
}
]
Run Code Online (Sandbox Code Playgroud)
for循环是唯一可行的方法吗?我热衷于某种方式使用Math.max.
我在项目中使用angularjs.
我从服务器获取了一系列对象.每个对象包含很少的属性,其中一个属性是date属性.
这是我从服务器获得的数组(在json中):
[
{
"Address": 25,
"AlertType": 1,
"Area": "North",
"MeasureDate": "2019-02-01T00:01:01.001Z",
"MeasureValue": -1
},
{
"Address": 26,
"AlertType": 1,
"Area": "West",
"MeasureDate": "2016-04-12T15:13:11.733Z",
"MeasureValue": -1
},
{
"Address": 25,
"AlertType": 1,
"Area": "North",
"MeasureDate": "2017-02-01T00:01:01.001Z",
"MeasureValue": -1
}
.
.
.
]
Run Code Online (Sandbox Code Playgroud)
我需要从阵列中获取最新日期.
从对象数组中获取最新日期的优雅方法是什么?
我有样本数据:
data = [
[1, 622, 782, 783, "2015-04-21"],
[2, 622, 782, 783, "2015-04-21"],
[3, 622, 782, 783, "2015-04-22"],
[4, 622, 782, 783, "2015-04-23"],
[5, 622, 782, 783, "2015-04-24"],
[6, 622, 782, 783, "2015-04-28"],
[7, 622, 782, 783, "2015-04-28"],
[8, 622, 782, 783, "2015-04-29"],
[9, 622, 782, 783, "2015-05-04"],
[10, 622, 782, 783, "2015-05-05"]
]
Run Code Online (Sandbox Code Playgroud)
如何从上述数据中获取最大日期值和最小日期值?数据可能不按排序顺序排列.
有一个数组:
var a = new Array();
Run Code Online (Sandbox Code Playgroud)
它包含这样的日期条目:'2012-09-12 09:20'等
我需要使用 javascript 查找最小和最大日期。此代码不适用于时间值。
var minT = Math.min.apply(Math, a);
var maxT = Math.max.apply(Math, a);
Run Code Online (Sandbox Code Playgroud)
如何在javascript中解决这个问题?这似乎很复杂,因为我对这门语言不是很熟悉。