Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

loadash sort by order of another array

var firstArray = ['asdf12','39342aa','12399','129asg',...];

// a collection which has these keys in each object like so:
var collection = [{guid: '39342aa', name: 'John'},{guid: '129asg', name: 'Mary'}, ... ];

const last = collection.length;

var sortedCollection = _.sortBy(collection, function(item){
  return firstArray.indexOf(item.guid) !== -1
  	? firstArray.indexOf(item.guid) : last;
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: get number from range line js 
Javascript :: $(getJson) returning error 
Javascript :: push only elements list into another list javascript 
Javascript :: how to make a modal stay center of screen 
Javascript :: GET req with js 
Javascript :: javascript remove all style values in div 
Javascript :: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project electronicbookshop: Compilation failure 
Javascript :: how to right plain text format file in node js 
Javascript :: /on in jquery 
Javascript :: javascript string includes 
Javascript :: react date picker disable past dates 
Javascript :: javascript alert get text 
Javascript :: get status bar height react native 
Javascript :: how to run different node app on server different domains 
Javascript :: joi schema for confirm password 
Javascript :: react delete button onclick 
Javascript :: toggle css class in javascript 
Javascript :: beautify json in html 
Javascript :: replace url without reload js 
Javascript :: laravel 419 
Javascript :: string.find javascript 
Javascript :: javascript sample list 
Javascript :: refresh current component angular 
Javascript :: get child routes using parent in angular 
Javascript :: how to set current date and time in jquery datetime-local 
Javascript :: node uuid 
Javascript :: neo4j create relationship between existing nodes 
Javascript :: javascript current date time 
Javascript :: css div at bottom of div 
Javascript :: javascript parse json string 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =