Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Sample test of Javascript Typed Arrays
<!DOCTYPE html>
<title>Javascript Typed Arrays</title>
<meta charset="UTF-8">
<script type="text/javascript" src=""></script>
<script type="text/javascript">
// Here's a sample string
let sample_string = "Hello World!"
// Get the raw numbers to save
let bytes = []
for(let i = 0;i < sample_string.length; i++){
// Put the numbers in 2 bytes each
let u16 = new Uint16Array(bytes)
// Save the string directly
// try putting u16 instead of sample_string below, and compare the outputs.
saveAs(new Blob([sample_string]),"output.txt")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment