Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

sort array of object by another value array in javascript

var sortOrder = [2,3,1,4],
    items     = [{id: 1}, {id: 2}, {id: 3}, {id: 4}];

items.sort(function (a, b) {
  return sortOrder.indexOf(a.id) - sortOrder.indexOf(b.id);
});
Comment

sort array of objects based on another array javascript

itemsArray.sort(function(a, b){  
  return sortingArr.indexOf(a) - sortingArr.indexOf(b);
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: node js send fcm 
Javascript :: javascript date methods 
Javascript :: get input type js 
Javascript :: javascript date time formating 
Javascript :: convert date online in moment js 
Javascript :: moment from seconds 
Javascript :: get authorization header javascript in my page 
Javascript :: button in vanilla js 
Javascript :: javascript video feed 
Javascript :: Arrays Comparison 
Javascript :: how to convert string into blob in javascript 
Javascript :: radio button onclick jquery 
Javascript :: js propagation stop 
Javascript :: regex for check if string is only empty or whitespace javascript 
Javascript :: javascript style multiple properties 
Javascript :: print placeholder value javascript 
Javascript :: json.parse what does it do 
Javascript :: javascript select first n elements from array 
Javascript :: js get json keys 
Javascript :: regex urls 
Javascript :: javascript array function 
Javascript :: .sort javascript 
Javascript :: get element ref react 
Javascript :: 3 letter months javascript array 
Javascript :: semantics ui complete responsive menu 
Javascript :: javascript squared 
Javascript :: jquery serialize with file upload 
Javascript :: generate random id javascript 
Javascript :: how to generate unique id in node js 
Javascript :: how to disable back js 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =