A QUICK USE CASE
• For example, you made a get request to your API, and it returned you a bunch of {objects} in {objects} also in {objects} in an [ParentArray] or {ParentObject}.
• Now you want to Sort them by Descending of price values. If price are same then you want to sort "props.id" values by Ascending which lives in second object inside the first object. If also "props.id" values are same then sort "props.anotherProps.anotherProps.id" values by Descending.
INSTALLATION
npm install arraybrain
METHODS & USAGE
// Before start, import the arraybrain first.;
Not: How to define a key property ?
Sample key ⇒ 'props.date=date|desc'
Explanation
props.date ⇒ is a simple js object iteration. Select date from prop.
After equal sign "="
date|desc ⇒ the props.date is a date property and I want to sort by descending
Performing a very simple sorting on Arrays sort
method
; ;;
Performing a complex sorting on Arrays with sort
method
Sort by using one key and if the sorted values are same than sort by using another key.
// Lets define objects inside an array also object inside in objects; ;
Performing very complex sorting on Arrays with smartSort
method
Sort the objects with given keys in the props array until the values are not same.
; ; ;
Performing very complex sorting on Objects with smartObjectSort
method
Sort Objects {} and get output as type of sorted Object or sorted Array.
; // We will sort this testing array, keep reading the example at the end of the line!; // This will return the same object as sorted; // This will return the object as sorted array// If you want to keep actual object's key as well, you should pass "true" parameter to the method. It will return the actual key as _arraybrainkey: key;