New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

sort-by-array

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sort-by-array

Sort an array of objects or sub-arrays using a reference array.

latest
Source
npmnpm
Version
0.2.6
Version published
Maintainers
1
Created
Source

sort-by-array

Sort an array of objects or sub-arrays using a reference list.

Quick example:

import sortByArray from 'sort-by-array';

const nameArray = [
  { name: 'Anne', order: { this: 'a' } },
  { name: 'Bob', order: { this: 'b' } },
  { name: 'Henry', order: { this: 'b' } },
  { name: 'Andrew', order: { this: 'd' } },
  { name: 'Jason', order: { this: 'c' } },
  { name: 'Thomas', order: { this: 'e' } },
  { name: 'Peter', order: { this: 'e' } },
];

const sortedObjectBy = ['b', 'e', 'e', 'b', 'a', 'd', 'c'];
const sortedNames = sortByArray(
  nameArray,
  sortingArray,
  'order.this',
  'exact',
);

const nestedArray = [
  ['Anne', '1'],
  ['Chris', '4'],
  ['Vero', '3'],
  ['Luca', 2],
  ['Masha', 2],
  ['Kosta', 2],
  ['Quang', 5],
];

const sortNestedBy = [5, '1', 2, '3', '4'];
const sortedArrays = sortByArray(nestedArray, sortNestedBy, 1);

Keywords

sort-object-array

FAQs

Package last updated on 10 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts