Array.prototype.sortByPath >= 0.1.5

Purpose

Sort by given paths

Syntax

Array#sortByPath ( Numberorder= -1 Stringpaths );

Parameters

order
Sort order: 1 for ascending, -1 for descending
paths
One path, an array of paths, or multiple arguments

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}]