cara memeriksa apakah string hanya berisi spasi di javascript

let str = "    ";
if (!str.replace(/\s/g, "").length) {
  console.log("string only contains whitespace (ie. spaces, tabs or line breaks)");
}
Pixel Freak