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 :: math.ceil 
Javascript :: twhat is a js promise 
Javascript :: mongoose encrypt database using mongoose encrypt package 
Javascript :: Angular Quick Tip: Binding Specific Keys to the Keyup and Keydown Events 
Javascript :: react-bootstrap problem-import new version 
Javascript :: get image from s3 bucket angular 
Javascript :: Create A React State 
Javascript :: ckeditor 5 on blur 
Javascript :: vue js data bind 
Javascript :: jquery get table 
Javascript :: reactjs sweet alert 
Javascript :: javascript removelastchild 
Javascript :: ionic vue use .env 
Javascript :: yup test string async 
Javascript :: print json object 
Javascript :: javascript loading animation 
Javascript :: change dictionary value in React js 
Javascript :: scroll div horizontally with move wheel js 
Javascript :: vue nexttick 
Javascript :: joi number of digits 
Javascript :: dotenv in node js 
Javascript :: The element.appendChild() Method 
Javascript :: object method in javascript 
Javascript :: array from js 
Javascript :: on:click svelte arguments 
Javascript :: object.create() js 
Javascript :: useEffect() Execute Function When React Component Loads 
Javascript :: find option values using javascript 
Javascript :: componentdidmount react hooks 
Javascript :: how to add a key in a react element 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =