Linked Questions
87 questions linked to/from Sort a JavaScript array based on another array
13
votes
1
answer
12k
views
Sort array of objects by array of IDs [duplicate]
Is it possible, rather easily, to sort an array of objects by an array of IDs? Here's an example:
[{
id: "A",
name: "John"
}, {
id: "B",
name: "Bobby"
}, {
id: "C",
name: "...
6
votes
2
answers
11k
views
Sort array containing objects based on another array [duplicate]
Possible Duplicate:
JavaScript - Sort an array based on another array of integers
Javascript - sort array based on another array
If I have an array like this:
['one','four','two']
And another ...
5
votes
3
answers
19k
views
How to sort array of objects with forEach loop javascript [duplicate]
I have an array that looks like this:
order = [ "foo", "bar", "baz" ];
This array contains the attribute values I would like to sort my array of objects by. I want to sort the data so that all the ...
-2
votes
4
answers
3k
views
Sort Javascript array by a given sequence of numbers [duplicate]
I have a Javascript array of object. Each of them has an integer property type in a range between 1 and 4. Depending on the client, I want to sort the array members by an individual number sequence of ...
3
votes
5
answers
111
views
Sort fixed array of objects by using another array [duplicate]
I have variable that defines the order of objects like this:
const order = ['large', 'medium', 'small'];
I want to match that order of data array objects using names from order array:
const data = [{...
2
votes
1
answer
749
views
How to sort an array based on arbitrary object values? [duplicate]
I have some weekday-based data as follows:
[{
"dayOfWeek": "TUESDAY",
"startTime": "19:30:00",
"endTime": "21:15:00"
}, {
"dayOfWeek": "SATURDAY",
"startTime": "19:15:00",
"...
2
votes
2
answers
166
views
Sort array by specific order [duplicate]
I have an array
peeps = [{name: "Mike", age: 31},{name: "Dave", age: 31},{name: "Delta", age: 31},{name: "Clint", age: 31}]
And I need to sort them by an ...
-4
votes
2
answers
604
views
Javascript sort an objects by another array [duplicate]
I have two arrays.
itemsArray =
[
{ id: 8, name: 'o'},
{ id: 7, name: 'g'},
{ id: 6, name: 'a'},
{ id: 5, name: 'k'},
{ id: 4, name: 'c'}
]
sortArray = [4,5]
How can i sort itemsArray by sortArray (...
1
vote
2
answers
242
views
How to sort an array of events by month in JavaScript? [duplicate]
How could I sort an array of events by the month they are occuring in?
For instance, I want to sort this events array:
[{ event: 'prom', month: 'MAY' },
{ event: 'graduation', month: 'JUN' },
{ ...
1
vote
4
answers
121
views
How to sort an array using Array.prototype.sort() by two properties? [duplicate]
How to sort an array using Array.prototype.sort() by type and currency in this order:
debit => credit => external => loan
and if there are several currencies in the same type, then arrange ...
0
votes
1
answer
273
views
JS sort by predefined string values [duplicate]
I have an array of items that I want to sort based on the category property:
const arr = [{
id: 1,
category: 'bar'
}, {
id: 4,
category: 'baz'
},
{
id: 5,
category: 'foo'
}]
What I want ...
0
votes
4
answers
132
views
Sorting array of objects by array of strings [duplicate]
So I have an array of objects similar to below:
var objs = [
{ key: 'address', value: '1234 street' },
{ key: 'nameAndTitle', value: 'John Smith, CEO' },
{ key: 'contactEmail', value: '...
0
votes
2
answers
201
views
JavaScript - Arbitrary Sort [duplicate]
I have an array like this:
var data = ['High', 'Low', 'Medium'];
This data array is created dynamically. So, it may have all 3 values or only 2 values or 1 value.
Regardless of the values in the ...
0
votes
4
answers
104
views
Sort an array of arrays based on another array [duplicate]
How can I sort an array of arrays based on another array?
Example:
const dataset = [
[ 'red', [{name: 'Apple car'}] ],
[ 'blue', [{name: 'Toothpiece'}] ],
[ 'orange', [{name: 'Sun'}] ],
[ '...
1
vote
2
answers
189
views
Typescript order array based on values of another array [duplicate]
Lets say I have a base array
let object2 = ["DotNet", "ETL", "Hadoop", "Java", "Oracle", "Pega", "MainFrame"]
I want to order this second array in the same order of the base array
let object1 = [{...