xxxxxxxxxx
// Writing methods: set<Type>(byteOffset, value, [littleEndian])
dataView.setInt32(byteOffset, intValue, littleEndian);
dataView.setFloat32(byteOffset, floatValue, littleEndian);
dataView.setString(byteOffset, stringValue, encoding);
// ...and more, where <Type> can be Int8, Uint8, Int16, Uint16, Int32, Uint32, Float32, or Float64.
xxxxxxxxxx
const buffer = new ArrayBuffer(bufferLength); // Create an ArrayBuffer with a specified length in bytes.
const dataView = new DataView(buffer); // Create a DataView to work with the ArrayBuffer.
xxxxxxxxxx
const buffer = new ArrayBuffer(4); // Create a 4-byte buffer
const dataView = new DataView(buffer); // Create a DataView to work with the buffer
dataView.setInt32(0, 12345, true); // Write a 32-bit integer with little-endian byte order
const readValue = dataView.getInt32(0, true); // Read the integer back
console.log(readValue); // Output: 12345