如何按每个条目右侧的语言对此 JSON 对象进行排序?
我正在使用 PhoneGap 和 jqTouch 创建一个 Android 应用程序,并且我有一个 JSON 对象,其中包含一个单词以及该单词所在的语言。如何使用 Javascript 按右侧的列(语言)按字母顺序排序?最终结果应该是南非荷兰语作为第一个条目,祖鲁语作为最后一个条目。
var languages = {
"Hello" : "English",
"Bonjour" : "French",
"Hola" : "Spanish",
"السّلام عليكم" : "Arabic",
"Haai" : "Afrikaans",
"Nei ho" : "Cantonese".
"Goddag" : "Danish",
"Goede dag" : "Dutch",
"Saluton" : "Esperanto",
"Hei" : "Finnish",
"Guten tag" : "German",
"Gia'sou" : "Greek",
"Aloha" : "Hawaiian",
"Hebrew" : "Shalom",
"Namaste" : "Hindi",
"Halo" : "Indonesian",
"Aksunai" : "Inuit",
"Dia dhuit" : "Irish",
"Salve" : "Spanish",
"Kon-nichiwa" : "Japanese",
"An-nyong Ha-se-yo" : "Korean",
"Mandarin" : "Ni hao",
"Hallo" : "Norweigan",
"Dzien' dobry" : "Polish",
"Jambo" : "Swahili",
"Hej" : "Swedish",
"Sa-wat-dee" : "Thai",
"Merhaba" : "Turkish",
"Vitayu" : "Ukrainian",
"Hylo" : "Welsh",
"Sholem aleychem" : "Yiddish",
"Sawubona" : "Zulu"
}
感谢你们的帮助:)
I am creating an Android app using PhoneGap and jqTouch, and I have a JSON object containing a word along with a language which that word is in. How can I sort this alphabetically, by the column on the right (the language), using Javascript? The end result should be Afrikaans as the first entry and Zulu as the last.
var languages = {
"Hello" : "English",
"Bonjour" : "French",
"Hola" : "Spanish",
"السّلام عليكم" : "Arabic",
"Haai" : "Afrikaans",
"Nei ho" : "Cantonese".
"Goddag" : "Danish",
"Goede dag" : "Dutch",
"Saluton" : "Esperanto",
"Hei" : "Finnish",
"Guten tag" : "German",
"Gia'sou" : "Greek",
"Aloha" : "Hawaiian",
"Hebrew" : "Shalom",
"Namaste" : "Hindi",
"Halo" : "Indonesian",
"Aksunai" : "Inuit",
"Dia dhuit" : "Irish",
"Salve" : "Spanish",
"Kon-nichiwa" : "Japanese",
"An-nyong Ha-se-yo" : "Korean",
"Mandarin" : "Ni hao",
"Hallo" : "Norweigan",
"Dzien' dobry" : "Polish",
"Jambo" : "Swahili",
"Hej" : "Swedish",
"Sa-wat-dee" : "Thai",
"Merhaba" : "Turkish",
"Vitayu" : "Ukrainian",
"Hylo" : "Welsh",
"Sholem aleychem" : "Yiddish",
"Sawubona" : "Zulu"
}
Thanks for your help guys :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JavaScript 不保证对象属性的任何顺序。因此,您需要创建一个数组,对每个条目进行数字索引。
例如:
然后,要按语言排序,您可以:
JavaScript does not guarantee any ordering of object properties. So you'll need to create an array which numerically indexes each entry.
E.g.:
Then, to sort by language, you can: