Sort Json Array with LoDash

你离开我真会死。 提交于 2019-12-01 04:04:15

You need to put the key in quotes only when calling sortBy. It doesn't have to be in quotes in the data itself.

_.sortBy(json, "key")

Also, your second parameter to map is wrong. It should be a function, but using pluck is easier.

_.pluck( _.sortBy(json, "key") , "value");
_.map(_.sortBy(json, 'key'), 'value');

NOTE: In the latest version of lodash, _.pluck no longer exists. Use _.map instead as a drop-in replacement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!