{id: 2, date: 1561036464327, week: "星期四"}
{id: 3, date: 1561083077921, week: "星期五"}
怎么比较这两条数据中date的大小,并能够返回这条数据
{id: 2, date: 1561036464327, week: "星期四"}
{id: 3, date: 1561083077921, week: "星期五"}
怎么比较这两条数据中date的大小,并能够返回这条数据
需要使用eval函数,代码如下所示
function compareDate(){
var data1="{id: 2, date: 1561036464327, week: '星期四'}";
var data2="{id: 3, date: 1561083077921, week: '星期五'}";
var data1Json=eval("("+data1+")");
var data2Json=eval("("+data2+")");
if(data1Json.date>data2Json.date){
return data1Json;
}
else {
return data2Json;
}
}