Underscore库
程序员文章站
2022-06-03 12:22:34
...
Underscore
测试html文档
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="./underscore.js"></script>
</head>
<body>
<body>
<script>
var type=[{key:2,value:"b",date:"2019-05-12"},{key:1,value:"a",date:"2019-06-15"},{key:2,value:"b",date:"2019-05-12"}]
//_的map方法
var ret =_.map(type,function(item){
return item.key;
})
//原生的sort排序
type.sort(function(a,b){
return new Date(a.date) - new Date(b.date);
})
console.log(type)
//_的sortBy的顺序排序方法
var retdate=_.sortBy(type,function(item){
return -new Date(item.date);
})
console.log(retdate)
</script>
</html>
下一篇: 位运算及诸技巧