I have a list of objects I wish to sort based on a field attr
of type string.(我有一个对象列表,希望根据字符串类型的字段attr
进行排序。)
I tried using -
(我尝试使用-
)
list.sort(function (a, b) {
return a.attr - b.attr
})
but found that -
doesn't appear to work with strings in JavaScript.(但发现-
在JavaScript中似乎不适用于字符串。) How can I sort a list of objects based on an attribute with type string?(如何根据具有字符串类型的属性对对象列表进行排序?)
ask by airportyh translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…