当前位置:网站首页>Array sorting num ranking merge in ascending order
Array sorting num ranking merge in ascending order
2022-07-05 15:18:00 【Front end cat】
let arr1 = [
{num:'7',name:' Xiaohong 7'},
{num:'6',name:' Small m'},
{num:'5',name:' Small d'},
{num:'4',name:' Small c'},
{num:'3',name:' Small f'},
{num:'2',name:' Small s'},
{num:'1',name:' Small 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 in ascending order
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)
})
// Will be small c Put it at the end of the array
let cIndex = crr.findIndex(value => value.name.includes(" Small 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)
边栏推荐
猜你喜欢
随机推荐
ionic cordova项目修改插件
CODING DevSecOps 助力金融企业跑出数字加速度
Garbage collection mechanism of PHP (theoretical questions of PHP interview)
Shanghai under layoffs
Huawei Hubble incarnation hard technology IPO harvester
The elimination strategy of redis
How can the boss choose programmers to help me with development?
30岁汇源,要换新主人了
Redis distributed lock principle and its implementation with PHP (1)
Can I pass the PMP Exam in 20 days?
爱可可AI前沿推介(7.5)
Hongmeng system -- Analysis from the perspective of business
【華為機試真題詳解】歡樂的周末
Leetcode: Shortest Word Distance II
MongDB学习笔记
Two Bi development, more than 3000 reports? How to do it?
SQL Server learning notes
Drive brushless DC motor based on Ti drv10970
I collect multiple Oracle tables at the same time. After collecting for a while, I will report that Oracle's OGA memory is exceeded. Have you encountered it?
Want to ask the big guy, is there any synchronization from Tencent cloud Mysql to other places? Binlog saved by Tencent cloud MySQL on cos









