This is my original JavaScripts Object
novels = {
"39912": "Conan's gramology investigator(柯南里的克学调查员)",
"40519": "Simulator: I predict the future in the last days(模拟器:我在末世预测未来)",
"40859": "Reborn Football Simulator(重生之足球模拟器)",
"41052": "Naruto comes to Marvel(降临漫威的火影忍者)",
"43681": "Uchiha's Life Simulator(宇智波的人生模拟器)",
"46128": "Life simulator, start with a maid(人生模拟器,开局一宫女)",
"9961541": "Konoha Gatekeeper I was overheard by Tsunade(木叶守门人我被纲手偷听了心声)",
"9982243": "King: My ultimate hit rate is 100%(王者:我的大招命中率百分百)",
"10061579": "Hokage: Tsunade is pregnant, I can only become stronger!(火影:纲手怀孕了,我只能变强!)",
"10064100": "Naruto: God-level sign-in starts with unlimited chakra(火影:神级签到从无限查克拉开始)",
"10064164": "Pokémon: Sign in at the beginning of the Koga Ninja Frog(神奇宝贝:开局签到甲贺忍蛙)",
"10064304": "Genocide Night, fortunately I have a ninja simulator(灭族之夜,还好我有忍者模拟器)",
"10064399": "Naruto: I can reach full level with one click(火影:我能一键满级)",
"10064576": "Naruto: My clone can evolve(火影:我的分身能进化)",
"10064579": "People in Konoha, start life simulator(人在木叶,开局人生模拟器)",
"10064599": "Naruto: Uchiha, the salted fish, was eavesdropped by Itachi(火影:咸鱼宇智波,被鼬偷听心声)",
"10064824": "The salted fish ninja was overheard by Orochimaru(咸鱼忍者,被大蛇丸偷听心声)",
"10064894": "Naruto: Sign in to Reaper's Scythe at the beginning, harvest wildly(火影:开局签到死神之镰,疯狂收割)",
"10065466": "Pirates: Sign in at the beginning of the Naruto character card(海贼:开局签到火影角色卡)",
"10072166": "Voice of Journey to the West: Beginning Guide Monkey King(西游心声:开局指引孙悟空)"
};
I want to sort it by value like this (i used notepad to make it)
novels = {
"39912": "Conan's gramology investigator(柯南里的克学调查员)"
"10064304": "Genocide Night, fortunately I have a ninja simulator(灭族之夜,还好我有忍者模拟器)"
"10061579": "Hokage: Tsunade is pregnant, I can only become stronger!(火影:纲手怀孕了,我只能变强!)"
"9982243": "King: My ultimate hit rate is 100%(王者:我的大招命中率百分百)"
"9961541": "Konoha Gatekeeper I was overheard by Tsunade(木叶守门人我被纲手偷听了心声)"
"46128": "Life simulator, start with a maid(人生模拟器,开局一宫女)"
"41052": "Naruto comes to Marvel(降临漫威的火影忍者)"
"10064100": "Naruto: God-level sign-in starts with unlimited chakra(火影:神级签到从无限查克拉开始)"
"10064399": "Naruto: I can reach full level with one click(火影:我能一键满级)"
"10064576": "Naruto: My clone can evolve(火影:我的分身能进化)"
"10064894": "Naruto: Sign in to Reaper's Scythe at the beginning, harvest wildly(火影:开局签到死神之镰,疯狂收割)"
"10064599": "Naruto: Uchiha, the salted fish, was eavesdropped by Itachi(火影:咸鱼宇智波,被鼬偷听心声)"
"10064579": "People in Konoha, start life simulator(人在木叶,开局人生模拟器)"
"10065466": "Pirates: Sign in at the beginning of the Naruto character card(海贼:开局签到火影角色卡)"
"10064164": "Pokémon: Sign in at the beginning of the Koga Ninja Frog(神奇宝贝:开局签到甲贺忍蛙)"
"40859": "Reborn Football Simulator(重生之足球模拟器)"
"40519": "Simulator: I predict the future in the last days(模拟器:我在末世预测未来)"
"10064824": "The salted fish ninja was overheard by Orochimaru(咸鱼忍者,被大蛇丸偷听心声)"
"43681": "Uchiha's Life Simulator(宇智波的人生模拟器)"
"10072166": "Voice of Journey to the West: Beginning Guide Monkey King(西游心声:开局指引孙悟空)"
}
i found this Sorting object property by values and but didn't work for me
i tried this
var sortarr = Object.entries(novels).sort((a,b) => (a[1]>b[1]?1:-1));
it become arrays and it sort well
[
[
"39912",
"Conan's gramology investigator(柯南里的克学调查员)"
],
[
"10064304",
"Genocide Night, fortunately I have a ninja simulator(灭族之夜,还好我有忍者模拟器)"
],
[
"10061579",
"Hokage: Tsunade is pregnant, I can only become stronger!(火影:纲手怀孕了,我只能变强!)"
],
[
"9982243",
"King: My ultimate hit rate is 100%(王者:我的大招命中率百分百)"
],
[
"9961541",
"Konoha Gatekeeper I was overheard by Tsunade(木叶守门人我被纲手偷听了心声)"
],
[
"46128",
"Life simulator, start with a maid(人生模拟器,开局一宫女)"
],
[
"41052",
"Naruto comes to Marvel(降临漫威的火影忍者)"
],
[
"10064100",
"Naruto: God-level sign-in starts with unlimited chakra(火影:神级签到从无限查克拉开始)"
],
[
"10064399",
"Naruto: I can reach full level with one click(火影:我能一键满级)"
],
[
"10064576",
"Naruto: My clone can evolve(火影:我的分身能进化)"
],
[
"10064894",
"Naruto: Sign in to Reaper's Scythe at the beginning, harvest wildly(火影:开局签到死神之镰,疯狂收割)"
],
[
"10064599",
"Naruto: Uchiha, the salted fish, was eavesdropped by Itachi(火影:咸鱼宇智波,被鼬偷听心声)"
],
[
"10064579",
"People in Konoha, start life simulator(人在木叶,开局人生模拟器)"
],
[
"10065466",
"Pirates: Sign in at the beginning of the Naruto character card(海贼:开局签到火影角色卡)"
],
[
"10064164",
"Pokémon: Sign in at the beginning of the Koga Ninja Frog(神奇宝贝:开局签到甲贺忍蛙)"
],
[
"40859",
"Reborn Football Simulator(重生之足球模拟器)"
],
[
"40519",
"Simulator: I predict the future in the last days(模拟器:我在末世预测未来)"
],
[
"10064824",
"The salted fish ninja was overheard by Orochimaru(咸鱼忍者,被大蛇丸偷听心声)"
],
[
"43681",
"Uchiha's Life Simulator(宇智波的人生模拟器)"
],
[
"10072166",
"Voice of Journey to the West: Beginning Guide Monkey King(西游心声:开局指引孙悟空)"
]
]
but when i try to make object with
sortobj = Object.fromEntries(sortarr);
it become unsorted like original (sort by key) instead of sort by value
novels = {
"39912": "Conan's gramology investigator(柯南里的克学调查员)",
"40519": "Simulator: I predict the future in the last days(模拟器:我在末世预测未来)",
"40859": "Reborn Football Simulator(重生之足球模拟器)",
"41052": "Naruto comes to Marvel(降临漫威的火影忍者)",
"43681": "Uchiha's Life Simulator(宇智波的人生模拟器)",
"46128": "Life simulator, start with a maid(人生模拟器,开局一宫女)",
"9961541": "Konoha Gatekeeper I was overheard by Tsunade(木叶守门人我被纲手偷听了心声)",
"9982243": "King: My ultimate hit rate is 100%(王者:我的大招命中率百分百)",
"10061579": "Hokage: Tsunade is pregnant, I can only become stronger!(火影:纲手怀孕了,我只能变强!)",
"10064100": "Naruto: God-level sign-in starts with unlimited chakra(火影:神级签到从无限查克拉开始)",
"10064164": "Pokémon: Sign in at the beginning of the Koga Ninja Frog(神奇宝贝:开局签到甲贺忍蛙)",
"10064304": "Genocide Night, fortunately I have a ninja simulator(灭族之夜,还好我有忍者模拟器)",
"10064399": "Naruto: I can reach full level with one click(火影:我能一键满级)",
"10064576": "Naruto: My clone can evolve(火影:我的分身能进化)",
"10064579": "People in Konoha, start life simulator(人在木叶,开局人生模拟器)",
"10064599": "Naruto: Uchiha, the salted fish, was eavesdropped by Itachi(火影:咸鱼宇智波,被鼬偷听心声)",
"10064824": "The salted fish ninja was overheard by Orochimaru(咸鱼忍者,被大蛇丸偷听心声)",
"10064894": "Naruto: Sign in to Reaper's Scythe at the beginning, harvest wildly(火影:开局签到死神之镰,疯狂收割)",
"10065466": "Pirates: Sign in at the beginning of the Naruto character card(海贼:开局签到火影角色卡)",
"10072166": "Voice of Journey to the West: Beginning Guide Monkey King(西游心声:开局指引孙悟空)"
};
i also try this
var arr=[];
xc=Object.entries(novels).sort((a,b) => (a[1]>b[1]?1:-1));
for (var prop in xc) {
if (xc.hasOwnProperty(prop)) {
arr.push({
[xc[prop][0]]: xc[prop][1]
});
}
}
It become many object in one array
arr =[
{
"39912": "Conan's gramology investigator(柯南里的克学调查员)"
},
{
"10064304": "Genocide Night, fortunately I have a ninja simulator(灭族之夜,还好我有忍者模拟器)"
},
{
"10061579": "Hokage: Tsunade is pregnant, I can only become stronger!(火影:纲手怀孕了,我只能变强!)"
},
{
"9982243": "King: My ultimate hit rate is 100%(王者:我的大招命中率百分百)"
},
{
"9961541": "Konoha Gatekeeper I was overheard by Tsunade(木叶守门人我被纲手偷听了心声)"
},
{
"46128": "Life simulator, start with a maid(人生模拟器,开局一宫女)"
},
{
"41052": "Naruto comes to Marvel(降临漫威的火影忍者)"
},
{
"10064100": "Naruto: God-level sign-in starts with unlimited chakra(火影:神级签到从无限查克拉开始)"
},
{
"10064399": "Naruto: I can reach full level with one click(火影:我能一键满级)"
},
{
"10064576": "Naruto: My clone can evolve(火影:我的分身能进化)"
},
{
"10064894": "Naruto: Sign in to Reaper's Scythe at the beginning, harvest wildly(火影:开局签到死神之镰,疯狂收割)"
},
{
"10064599": "Naruto: Uchiha, the salted fish, was eavesdropped by Itachi(火影:咸鱼宇智波,被鼬偷听心声)"
},
{
"10064579": "People in Konoha, start life simulator(人在木叶,开局人生模拟器)"
},
{
"10065466": "Pirates: Sign in at the beginning of the Naruto character card(海贼:开局签到火影角色卡)"
},
{
"10064164": "Pokémon: Sign in at the beginning of the Koga Ninja Frog(神奇宝贝:开局签到甲贺忍蛙)"
},
{
"40859": "Reborn Football Simulator(重生之足球模拟器)"
},
{
"40519": "Simulator: I predict the future in the last days(模拟器:我在末世预测未来)"
},
{
"10064824": "The salted fish ninja was overheard by Orochimaru(咸鱼忍者,被大蛇丸偷听心声)"
},
{
"43681": "Uchiha's Life Simulator(宇智波的人生模拟器)"
},
{
"10072166": "Voice of Journey to the West: Beginning Guide Monkey King(西游心声:开局指引孙悟空)"
}
]
i try merge it to become object with this
numn = {...arr[0],...arr[1],...arr[2],...arr[3],...arr[4],...arr[5],...arr[6],...arr[7],...arr[8],...arr[9],...arr[10],...arr[11],...arr[12],...arr[13],...arr[14],...arr[15],...arr[16],...arr[17],...arr[18],...arr[19],...arr[20]
};
then it become like original without sorting value
I search and look for many answer but i only saw (how to sort object key) but i don't find any answer about sort object value that work for my javascript object
Sorry, because my language is not English. So, i don't know how to explain in short then my question become very long.
swap=Object.fromEntries(Object.entries(Object.keys(novels).reduce((a, key) => ({...a,[ch[key]]: key}),{})).sort());
Edit: I finally found answer by swap key and value
novels ={
"Conan's gramology investigator(柯南里的克学调查员)": "39912",
"Genocide Night, fortunately I have a ninja simulator(灭族之夜,还好我有忍者模拟器)": "10064304",
"Hokage: Tsunade is pregnant, I can only become stronger!(火影:纲手怀孕了,我只能变强!)": "10061579",
"King: My ultimate hit rate is 100%(王者:我的大招命中率百分百)": "9982243",
"Konoha Gatekeeper I was overheard by Tsunade(木叶守门人我被纲手偷听了心声)": "9961541",
"Life simulator, start with a maid(人生模拟器,开局一宫女)": "46128",
"Naruto comes to Marvel(降临漫威的火影忍者)": "41052",
"Naruto: God-level sign-in starts with unlimited chakra(火影:神级签到从无限查克拉开始)": "10064100",
"Naruto: I can reach full level with one click(火影:我能一键满级)": "10064399",
"Naruto: My clone can evolve(火影:我的分身能进化)": "10064576",
"Naruto: Sign in to Reaper's Scythe at the beginning, harvest wildly(火影:开局签到死神之镰,疯狂收割)": "10064894",
"Naruto: Uchiha, the salted fish, was eavesdropped by Itachi(火影:咸鱼宇智波,被鼬偷听心声)": "10064599",
"People in Konoha, start life simulator(人在木叶,开局人生模拟器)": "10064579",
"Pirates: Sign in at the beginning of the Naruto character card(海贼:开局签到火影角色卡)": "10065466",
"Pokémon: Sign in at the beginning of the Koga Ninja Frog(神奇宝贝:开局签到甲贺忍蛙)": "10064164",
"Reborn Football Simulator(重生之足球模拟器)": "40859",
"Simulator: I predict the future in the last days(模拟器:我在末世预测未来)": "40519",
"The salted fish ninja was overheard by Orochimaru(咸鱼忍者,被大蛇丸偷听心声)": "10064824",
"Uchiha's Life Simulator(宇智波的人生模拟器)": "43681",
"Voice of Journey to the West: Beginning Guide Monkey King(西游心声:开局指引孙悟空)": "10072166"
}