我有以下多维数组:
const users = [
[
1020,
"10-FEB-2019",
"ajd",
"Mary",
"jones",
"a@gmail.com",
"25 main Lane",
"brooklyn",
"NY",
"11210",
"5165551212",
"MEMB",
"alk",
"14-FEB-2019",
93.35
],
[
1010,
"08-FEB-2019",
"dak",
"Daisy",
"smith",
"d@gmail.com",
"62 stone Drive",
"brooklyn",
"NY",
"11210",
"5165551212",
"ADMIN",
"ERR",
"19-MAR-2019",
71.487
],
[
1000,
"05-FEB-2019",
"alk",
"Arnold",
"smith",
"a@gmail.com",
"62 stone Drive",
"brooklyn",
"NY",
"11210",
"5165551212",
"ADMIN",
"alk",
"14-FEB-2019",
203.41
]
]
我想按姓氏(索引4)对这个数组进行排序-琼斯,史密斯,史密斯。
我尝试了这个var sorted = _.sortBy(users[4]);
,但是没有用。
答案 0 :(得分:0)
您可以将_.sortBy()
或_.orderBy()
与要排序的“列”的索引一起使用:
const users = [[1020,"10-FEB-2019","ajd","Mary","jones","a@gmail.com","25 main Lane","brooklyn","NY","11210","5165551212","MEMB","alk","14-FEB-2019",93.35],[1010,"08-FEB-2019","dak","Daisy","smith","d@gmail.com","62 stone Drive","brooklyn","NY","11210","5165551212","ADMIN","ERR","19-MAR-2019",71.487],[1000,"05-FEB-2019","alk","Arnold","smith","a@gmail.com","62 stone Drive","brooklyn","NY","11210","5165551212","ADMIN","alk","14-FEB-2019",203.41]]
const result = _.sortBy(users, 4)
console.log(result)
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.js"></script>