Js Linq
Linq是对前端集合变量进行操作的一种技术框架,引用文件linq.min.js。 var myList = [ { Name: "Victor", Age: 28 }, { Name: "Jack", Age: 30 }, { Name: "Simon", Age: 26 }, { Name: "Hellen", Age: 27 }, { Name: "Felix", Age: 28 } ]; 1.where条件筛选 var results=myList .where(function(t){return t.Name=="Victor"}); //返回[{ Name: "Victor", Age: 28 }] 2.select获取指定的属性 var results=myList .select(function(t){return t.Age}); //返回[28, 30, 26, 27, 28] 3.orderBy排序 var results=myList.orderBy(function(t){return t.Age}); //返回[{ Name: "Simon", Age: 26 }, { Name: "Hellen", Age: 27 },{ Name: "Victor", Age: 28 }, { Name: "Felix", Age: 28 }, { Name: "Jack", Age: 30 }] 4.distinct去重 var results=myList.distinct(function(a,b){return a.Age==b.Age}); //[{ Name: "Simon", Age: 26 }, { Name: "Hellen", Age: 27 },{ Name: "Victor", Age: 28 }, { Name: "Jack", Age: 30 }] 5.forEach遍历 myList.forEach(function(value,index){console.log("Name:"+value.Name+"Age:"+value.Age);})
posted on 2019-04-16 16:59 赢在当下_Victor 阅读(196) 评论(0) 编辑 收藏 举报