1、方法
sameArray(data, field) {
let array = []
let tmp = []
let vlaue = ''
data = data.sort(function (a, b) {
const start = a[field]
const end = b[field]
return start < end ? -1 : 1
})
if (data.length) {
vlaue = data[0][field]
}
data.forEach((item) => {
if (item[field] === vlaue) {
tmp.push(item)
} else {
vlaue = item[field]
array.push(tmp)
tmp = [item]
}
})
array.push(tmp)
return array
},