Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

move element to the top of list javascript

const data= [{code:"001",name:"Kirk-Patrick Brown"},{code:"002",name:"Sara Brown"},{code:"003",name:"Joe Frazer"}];

const firstItem = "003";
data.sort((x,y)=>{ return x.code === firstItem ? -1 : y.code === firstItem ? 1 : 0; });

console.log(data);
 
PREVIOUS NEXT
Tagged: #move #element #top #list #javascript
ADD COMMENT
Topic
Name
5+9 =