In a previous post I’ve shared with you a JavaScript function that I’m using in order to easily access object’s properties that go from 1 to n levels of depth. Now, I’ve decided to extend on that post, and show you how I’m using the same method to achieve the JavaScript array sorting using dynamic properties.
First of all, go to my previous post to see how the getRecordField function is defined and used.
Next, let’s see how the advancedDynamicSort function, that we’ll use for array sorting, looks like:
Sample use:
I have to give credit to the original creator of the dynamicSort function, Ege Özcan, and his StackOverflow answer. All I did in the end was adjusting his method to work with my function that dynamically reads object’s properties in order to make the sorter even more flexible.
That’s it, I hope you’ll find this useful, and if you have any suggestions or critique, feel free to drop me a line in the comments below.