change array index position in javascript by up and down click
// move up by 1 postion in Array
const moveUp=(id)=> {
let index = arr.findIndex(e => e.id == id);
if (index > 0) {
let el = arr[index];
arr[index] = arr[index - 1];
arr[index - 1] = el;
}
}
// move dwon by 1 postion in Array
const moveDown=(id)=> {
let index = arr.findIndex(e => e.id == id);
if (index !== -1 && index < arr.length - 1) {
let el = arr[index];
arr[index] = arr[index + 1];
arr[index + 1] = el;
}
}
Also in JavaScript:
- http request without a library in javascript
- express req get json
- read xlsx file in angular 5
- how to make an object in p5 go right to left with keycCicked p5
- how to get json array response in retrofit
- javascript date parse yyyy-mm-dd
- json_extract in non native query
- json-server localhost
- script refresh js
- converting object to array in js
- add jquery cdn
- javascript array push object
- react $ r component instance console
- boucle for in js
- react.createref()
- binary to ascii javascript
- angular add bootstrap
- trigger input javascript
- add in to array mongoose
- javascript remove json element
- service worker.js
- Appending the option element using jquery each function
- update node two versions mac
- javascript dispatch a custom event