One-Line answer.
itemsArray.sort(function(a, b){
return sortingArr.indexOf(a) - sortingArr.indexOf(b);
});
Or even shorter:
itemsArray.sort((a, b) => sortingArr.indexOf(a) - sortingArr.indexOf(b));
More Related Contents:
- Running python on client side
- JavaScript and getElementById for multiple elements with the same ID
- D3.js Drawing geojson incorrectly
- Scroll to an element with jQuery
- Idiomatically find the number of occurrences a given value has in an array
- How do I convert String to Number according to locale (opposite of .toLocaleString)?
- Using number as “index” (JSON)
- How can I show a hidden div when a select option is selected?
- Search recursively for value in object by property name
- With JavaScript, can I change the Z index/layer of an SVG element?
- Decode UTF-8 with Javascript
- pass post data with window.location.href
- Why and when to use default export over named exports in es6 Modules?
- Fetching all (javascript) global variables in a page
- How to get the tag HTML with JavaScript / jQuery?
- How to make Google Chrome JavaScript console persistent?
- How to make jQuery to not round value returned by .width()?
- How to set ChartJS Y axis title?
- callback function meaning
- Object.getOwnPropertyNames vs Object.keys
- When value is assigned to components state, why console.log prints the previous state?
- javascript: convert two dimensional array to array of objects using the first ‘row’ to define properties
- Force showing the “Save as” dialog box when downloading a file
- Adding text to beginning of each array element
- Handling multiple files from an input element in an array with Google Apps Script
- Which types of queues are in event loop?
- How do you force your Javascript event to run first, regardless of the order in which the events were added?
- JQuery AutoComplete, manually select first searched item and bind click [duplicate]
- Google maps responsive resize
- Variation of e.touches, e.targetTouches and e.changedTouches