The name to sort by can be the field name OR a function, so pass a function that does a lower-case conversion.
var sorted = _.sortBy(array, function (i) { return i.name.toLowerCase(); });
should do the trick.
Don't use _.sortBy for this. The correct way to sort strings alphabetically is to use localeCompare. Here's an example in pure Javascript:
['Z', 'A','z','á', 'V'].sort(function(a, b){
return a.localeCompare(b, undefined /* Ignore language */, { sensitivity: 'base' })
});
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With