
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
sort-array-by-key
Advanced tools
A Typescript helper function to sort a typed array of objects by a specified element key
npm install sort-array-by-key --save
or
yarn add sort-array-by-key
sortArrayByKey<T>(arr:T[]);
arr:
Required typed Array value of type T[]. Type defaults to Record<any, any>.key:
Required value of type keyof T, upon which the items in the array are sorted by their corresponding values.ascending:
Optional value of type boolean. Determines whether the elements of the arr value are sorted in ascending order. Defaults to truesortArrayByKey will return a reference to the original arr array, of type T[], sorted by key values.Import the sortArrayByKey function
import sortArrayByKey from "sort-array-by-key";
or
const sortArrayByKey = require("sort-array-by-key")
Sample implementation
type User = {
name: string;
age: number;
};
const userList: User[] = [
{ name: 'Sally', age: 43 },
{ name: 'Wally', age: 13 },
{ name: 'Hally', age: 73 },
{ name: 'Cally', age: 23 },
];
// returns
/**
[
{ name: 'Wally', age: 13 },
{ name: 'Cally', age: 23 },
{ name: 'Sally', age: 43 },
{ name: 'Hally', age: 73 },
]
*/
const sortedUserList = sortArrayByKey<User>(userList, 'age');
FAQs
A Typescript helper function to sort a typed array of objects by a specified element key
We found that sort-array-by-key demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.