function checkEndian() {
  const arrayBuffer = new ArrayBuffer(2);
  const uint8Array = new Uint8Array(arrayBuffer);
  const uint16array = new Uint16Array(arrayBuffer);

  uint8Array[0] = 0xaa; // set first byte
  uint8Array[1] = 0xbb; // set second byte

  if (uint16array[0] === 0xbbaa) {
    return "little endian";
  }
  if (uint16array[0] === 0xaabb) {
    return "big endian";
  }
  // The most common architectures (x86 and ARM) are both little endian, so just assume that.
  console.error("Can not determine platform endianness, assuming little endian");
  return "little endian";
}
JavaScript clamped arrays will follow the byte ordering of their platform (either little-
or big endian).
@returns {string} "little endian" if byte ordering starts to the right, or
"big endian" if byte ordering starts from the left.