(ES6) ES6 (2016)

TypedArr (TA09)

   1:  const buffer = new ArrayBuffer(4);
   2:  const view = new DataView(buffer);
   3:  view.setUint32(0, 12345, false); // false for big-endian
   4:  
   5:  // Get the byte array
   6:  const byteArray = new Uint8Array(buffer);
   7:  console.log(byteArray); // Output: Uint8Array [ 0, 0, 48, 57 ] (big-endian)
   8:  
   9:  // Convert to little-endian by reversing the byte array
  10:  const littleEndianArray = Array.from(byteArray).reverse();
  11:  console.log(littleEndianArray); // Output: [57, 48, 0, 0] (little-endian)



 convert a big-endian byte array to a little-endian byte array (and vice versa) by using the Array.reverse()



 Uint8Array(4) [ 0, 0, 48, 57 ]
 [ 57, 48, 0, 0 ]





TypedArr context:






ES6 context:




Binary context:



Comments ( )
Link to this page: http://www.vb-net.com/JavascriptES6/TA09.htm
< THANKS ME>