Thursday, December 1, 2022

How to move item in an array to last position in javascript.

const arrayList = ['1', '2', '3', '5', '0'];
const moveThreeToEnd = (arrayList) => {
return arrayList.filter(item => item !== '3').concat(arrayList.filter(item => item === '3'))

}

console.log(array list); //['1', '2', '3', '5', '0' ];
console.log(moveThreeToEnd(array list)); // ['1', '2', '5', '0', '3'];

No comments:

Post a Comment