let arr1 = [
{num:'7',name:'小红7'},
{num:'6',name:'小m'},
{num:'5',name:'小d'},
{num:'4',name:'小c'},
{num:'3',name:'小f'},
{num:'2',name:'小s'},
{num:'1',name:'小e'},
]
let arr2 = [
{ranking:'1',grade:'10'},
{ranking:'2',grade:'9'},
{ranking:'3',grade:'8'},
{ranking:'7',grade:'4'},
{ranking:'4',grade:'7'},
{ranking:'5',grade:'6'},
{ranking:'6',grade:'5'},
]
// num ranking 按升序
let arr1Sort = arr1.sort((a,b)=>{
return a.num -b.num
})
let arr2Sort = arr2.sort((a,b)=>{
return a.ranking -b.ranking
})
console.log("arr1Sort ",arr1Sort ,arr2Sort )
let crr = []
arr2Sort.forEach((item, i) => {
console.log(item)
let obj = {
...item,
name: arr1Sort[i].name
}
crr.push(obj)
})
// 将小c 提出来放在数组的末尾
let cIndex = crr.findIndex(value => value.name.includes("小c"))
let c = crr[cIndex]
crr.splice(cIndex, 1)
let name = []
let val = []
crr.forEach((item)=>{
name.push(item.name)
val.push(item.grade)
})
crr.push(c)
console.log(crr)
console.log(c)