From 3458a836f51aa5ac8ef1d9f0f50703feba566dc7 Mon Sep 17 00:00:00 2001 From: laurenceks <69108396+laurenceks@users.noreply.github.com> Date: Fri, 7 Aug 2020 08:56:34 +0100 Subject: [PATCH] Added support for sorting an array of objects using myObject.sortKey --- naturalSort.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/naturalSort.js b/naturalSort.js index 8bdc024..859c1bb 100644 --- a/naturalSort.js +++ b/naturalSort.js @@ -13,8 +13,8 @@ function naturalSort (a, b) { return (naturalSort.insensitive && ('' + s).toLowerCase() || '' + s).replace(sre, ''); }, // convert all to strings strip whitespace - x = i(a), - y = i(b), + x = i(a.sortField || a), //.sortField for sorting array of objects - set key to whatever native key to compare + y = i(b.sortField || b), // chunk/tokenize xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'), yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),