Search
 
SCRIPT & CODE EXAMPLE
 

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);
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript filter map array of objects 
Javascript :: Hide angular element on button click 
Javascript :: react native dimensions 
Javascript :: js add function to array 
Javascript :: javascript cancel scroll 
Javascript :: javascript foreach break 
Javascript :: javascript get client page title 
Javascript :: json_decode javascript 
Javascript :: @apify/http-request 
Javascript :: how to change html element in javascript 
Javascript :: javascript convert number to spreadsheet column 
Javascript :: concat array javascript 
Javascript :: tooltip in chakra ui 
Javascript :: js get index from foreach 
Javascript :: search string for character javascript 
Javascript :: How to create sequelize connection in javascript 
Javascript :: eliminar comillas de un string javascript 
Javascript :: JS stack array backwards 
Javascript :: typeof javascript 
Javascript :: convert json into map in java example 
Javascript :: multi ternary operation in javascript 
Javascript :: how to assert in javascript 
Javascript :: react-loader-spinner 
Javascript :: vue axios post return json data 
Javascript :: make property read-only javascript 
Javascript :: javaScript setHours() Method 
Javascript :: string into json javascript 
Javascript :: string match method 
Javascript :: static js 
Javascript :: While resolving: gatsby-starter-ghost@2.0.0 npm ERR! Found: react@17.0.2 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =