var temp=[{name:"kitty",age:31},{name:"ff",age:22},{name:"kitty",age:44}] var temp1={ ct1:{name:"kitty",age:31}, ct2:{name:"ff",age:22}, ct3:{name:"kitty",age:44} } let hh = Immutable.fromJS(temp); //list let hh1=Immutable.fromJS(temp1) //map
.reverse: 倒排 ,支持list ,map
let reverse=hh.reverse() //[{"name":"kitty","age":44},{"name":"ff","age":22},{"name":"kitty","age":31}] let resverse1=hh1.reverse() //{"ct3":{"name":"kitty","age":44},"ct2":{"name":"ff","age":22},"ct1":{"name":"kitty","age":31}}
.groupBy:分組 支持 list 和 map
let groupBy=hh.groupBy(function(a,b,c){ return a.get("name")+"_ic" }) //{"kitty_ic":[{"name":"kitty","age":31},{"name":"kitty","age":44}],"ff_ic":[{"name":"ff","age":22}]} let groupBy1=hh1.groupBy(function(a,b,c){ return a.get("name")+"_ic" }) //{"kitty_ic":{"ct1":{"name":"kitty","age":31},"ct3":{"name":"kitty","age":44}},"ff_ic":{"ct2":{"name":"ff","age":22}}}
.sortBy:排序 支持 list 和 mapjavascript
let sortBy=hh.sortBy(function(a,b,c,d){ return -1*a.get("age") }) //[{"name":"kitty","age":44},{"name":"kitty","age":31},{"name":"ff","age":22}] let sortBy1=hh1.sortBy(function(a,b,c,d){ return -1*a.get("age") }) //{"ct3":{"name":"kitty","age":44},"ct1":{"name":"kitty","age":31},"ct2":{"name":"ff","age":22}}
.filter:返回經過真值檢測的元素值 支持 list 和 mapjava
let filter=hh.filter(function(a,b,c){ if(a.get("name")=="ff"){ return true } })//[{"name":"ff","age":22}] let filter1=hh1.filter(function(a,b,c){ if(a.get("name")=="ff"){ return true } })//{"ct2":{"name":"ff","age":22}}
.filterNot:返回不經過真值檢測的元素值 支持 list 和 mapspa
// filterNot:返回不經過真值檢測的元素值 支持 list 和 map let filterNot=hh.filterNot(function(a,b,c){ if(a.get("name")=="ff"){ return true } })//[{"name":"kitty","age":31},{"name":"kitty","age":44}] let filterNot1=hh1.filterNot(function(a,b,c){ if(a.get("name")=="ff"){ return true } })//{"ct1":{"name":"kitty","age":31},"ct3":{"name":"kitty","age":44}}
.map 支持 list 和 mapblog
//map 支持 list 和 map let map=hh.map((a,b,c)=>{ return a.get("name") })//["kitty","ff","kitty"] let map1=hh1.map((a,b,c)=>{ return a.get("name") })//{"ct1":"kitty","ct2":"ff","ct3":"kitty"}
.merge排序
//merge let tt1={ct1:{name:"",age:""},ct4:{name:"qq",age:42}} let merge1=hh1.merge(tt1) //{"ct1":{"name":"","age":""},"ct2":{"name":"ff","age":22},"ct3":{"name":"kitty","age":44},"ct4":{"name":"qq","age":42}}
.mergeDeep ip
//mergeDeep let ttDeep=[{name:"changed",qq:"add"},{},{},{qq:"add"}] let mergeDeep=hh.mergeDeep(ttDeep) //[{"name":"changed","age":31,"qq":"add"},{"name":"ff","age":22},{"name":"kitty","age":44},{"qq":"add"}] let ttDeep1={ct1:{name:"changed",qq:"add"},ct4:{name:"add"}} let mergeDeep1=hh1.mergeDeep(ttDeep1) //{"ct1":{"name":"","age":""},"ct2":{"name":"ff","age":22},"ct3":{"name":"kitty","age":44},"ct4":{"name":"qq","age":42}}