lequanghuylc / array-objects-sort

JS package module that sorts array of objects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

array-objects-sort

  • Sort with many priorities
  • Sort with descending and ascending

usage

Example list:

    const list = [
        {  
            a: "string",
            b: "number",
            c: "string",
            d: "string",
            e: "string"
        }
    ]

Usage:

    const SortList = require("array-objects-sort");

    const options = [
        {
            key: "a",
            priority: ["value_of_a_will_sort_at_top", "value_of_a_behind", "value_of_a_behind", ...]
        },
        {
            key: "b",
            priority: ["desc"] // ["asc"]
        },
        {
            key: "c",
            priority: ["value_of_c", ["this_two_value", "will_be_treated_as_equal_while_sorting"] , ...]
        },
    ];

    const thisSort = new SortList(options);
    const newSortedList = thisSort.sort(list);
    console.log(newSortedList);

About

JS package module that sorts array of objects


Languages

Language:JavaScript 100.0%