- 将一个数组按一定规则拆分成两个数组
//第一个数组前五条,剩下的分在第二个数组里
baseArray:[
{
name: '10'
},
{
name: '20'
},
{
name: '30'
},
{
name: '40'
},
{
name: '50'
},
{
name: '60'
},
{
name: '70'
},
{
name: '80'
},
{
name: '90'
},
{
name: '100'
}
],
oddArr: [],
eventArr: []
getArr(){
this.oddArr = this.baseArray.slice(0,5)
this.eventArr = this.baseArray.slice(5)
},
- 奇数偶数拆分
baseArray:[1,2,3,4,5,6]
getArr(){
this.oddArr = this.baseArray.filter((item)=> item % 2 === 1)
this.eventArr = this.baseArray.filter((item)=> item % 2 === 0)
},
网友评论