I would like to sort a JSON array given a certain order from an array representing a name/value column. An example would be:
data = [
{
First: "John",
Last: "Doe",
Age: 23
},
{
First: "Sue",
Last: "San",
Age: 13
},
{
First: "Kyle",
Last: "Wafer",
Age: 87
}
];
var sortBy = ["San", "Wafer", "Doe"];
So that my output would be:
var newData = [
{
First: "Sue",
Last: "San",
Age: 13,
},
{
First: "Kyle",
Last: "Wafer",
Age: 87,
},
{
First: "John",
Last: "Doe",
Age: 23,
}
];
Is it possible to implement using D3.js or basic JavaScript without complicated for loops? Thank you.