JSFiddle - React, Tailwind, and code Playground

by trishantpahwa

JavaScript

let arr = [];
const count = 10;

if (count <= 4) {
  for (let i = 0; i < count; i++) {
    arr.push(i);
  }
} else {
  arr = [1, 2, '...', count - 1, count];
}
console.log(arr);