Array.prototype.sortByPath >= 0.1.5

Purpose

Sort by given paths

Syntax

Array#sortByPath ( Numberorder= -1Stringpaths );

Parameters

order

Sort order: 1 for ascending, -1 for descending

paths

One path, an array of paths, or multiple arguments

Return values

Examples

Sort the given path

var arr = [	{a: 3},
        	{a: 1},
        	{a: 2},
        	{a: 0}];

arr.sortByPath('a');
>>> [{a: 3}, {a: 2}, {a: 1}, {a: 0}]

Sort ascending

var arr = [	{a: 3},
        	{a: 1},
        	{a: 2},
        	{a: 0}];

arr.sortByPath(1, 'a');
>>> [{a: 0}, {a: 1}, {a: 2}, {a: 3}]

Sort multiple paths

var arr = [	{a: 0, b: 1},
        	{a: 0, b: 0},
        	{a: 5, b: 1},
        	{a: 5, b: 0}];

arr.sortByPath(['a', 'b']);
>>> [{a: 5, b: 1}, {a: 5, b: 0}, {a: 0, b: 1}, {a: 0,b: 0}]

Comments

Errol

Your site has excellent content. I bookmarked the site

Errol

I discovered your web site from Google as well as I need to say it was a fantastic discover. Thanks!

Archer

I discovered your internet site from Google and also I need to state it was a wonderful locate. Thanks!