DEV Community

Discussion on: Javascript Array Condensing

Collapse
 
ashishsurana profile image
Ashish Surana

How about this one :p

const arr = [0, 0, 0, 4, 5, 1, 0, 5, 2, 0, 5];

Object.assign(Array(arr.length).fill(0), arr.filter(Boolean));

// [4, 5, 1, 5, 2, 5, 0, 0, 0, 0, 0]