JSFiddle - React, Tailwind, and code Playground

by Anurag Udasi

JavaScript

Array.prototype.removeZeroes = function() {
	let newArray = [];
  for (let item of this) {
  	if (item) { newArray.push(item); }
  }
  for (let i = 0; i < newArray.length; i++) {
  	this[i] = newArray[i];
  }
  this.length = newArray.length;
  return this;
};

let x = [1,2,3,0,4,0,5];
x.removeZeroes();
window.alert(x);