JSFiddle - React, Tailwind, and code Playground

by Chintan Upadhayay

HTML

<a href="#one" class="hash">One</a> 
<div>
    <p>some text</p>
</div>
<a href="#two" class="hash">Two</a> 
<div>
    <p>some text</p>
</div>
<a href="#three" class="hash">Three</a> 
<div>
    <p>some text</p>
</div>

CSS

div {
    height: 400px;
}

JavaScript

var array = [  {   ID: 168,   NAME: "First name",   CODE: "AD"  },  {   ID: 167,   NAME: "Second name",   CODE: "CC"  },  {   ID: 169,   NAME: "Third name",   CODE: "CCM"  },  {   ID: 170,   NAME: "Fourth name",   CODE: "CR"  }],
    item_order = [170,167,168,169];

array.sort((a, b) => item_order.indexOf(a.ID) - item_order.indexOf(b.ID));

console.log(array);