An ArrayBuffer is more than just a simple array. It contains raw binary data. This is very useful for direct memory manipulation and conserving space.

When you create a normal array, you won't get a proper set of contiguous memory in many cases since arrays can contain any combination of different kinds of objects. This is useful when you have dynamic data and multiple types together (frequently happens in JS) but is not so useful when you know the exact layout of memory that you need.

This also allows you to view the data at the byte level. For example, it's pretty common in binary data formats to have a n byte long identifier number, an m byte long field telling you how many bytes are used for this field, and m' bytes of data that actually makes up the data field.

[ identifier ][ bytes of data ][ data ]

With an ArrayBuffer, you have the option of moving through that data on the byte level by using various Views. A regular array doesn't allow you to move through the data with that level of granularity because no guarantees are made about the memory layout.

Finally, because you are telling the compiler/interpreter exactly how much space you're going to use and exactly how you're going to view it, it can do much more advanced optimizations when working with that data. When iterating through that data, it doesn't have to make calculated leaps through memory. Instead, it knows exactly how far to move ahead in memory to find the next data point.

As for what Uint8Array is, it's a typed array. Essentially, it tells the compiler/interpreter that you will be accessing this data exclusively as 8-bit uints which, again, allows it to make better optimizations. Then you can use standard array indexing on it (arr[0], arr[1], etc.) and you'll be getting back the equivalent uint values out of the array.

TL;DR They take less space when the exact data format is known, allows you to move more exactly through your data and gives the compiler/interpreter greater options for optimization.

Answer from Mike Cluck on Stack Overflow
Top answer
1 of 1
41

An ArrayBuffer is more than just a simple array. It contains raw binary data. This is very useful for direct memory manipulation and conserving space.

When you create a normal array, you won't get a proper set of contiguous memory in many cases since arrays can contain any combination of different kinds of objects. This is useful when you have dynamic data and multiple types together (frequently happens in JS) but is not so useful when you know the exact layout of memory that you need.

This also allows you to view the data at the byte level. For example, it's pretty common in binary data formats to have a n byte long identifier number, an m byte long field telling you how many bytes are used for this field, and m' bytes of data that actually makes up the data field.

[ identifier ][ bytes of data ][ data ]

With an ArrayBuffer, you have the option of moving through that data on the byte level by using various Views. A regular array doesn't allow you to move through the data with that level of granularity because no guarantees are made about the memory layout.

Finally, because you are telling the compiler/interpreter exactly how much space you're going to use and exactly how you're going to view it, it can do much more advanced optimizations when working with that data. When iterating through that data, it doesn't have to make calculated leaps through memory. Instead, it knows exactly how far to move ahead in memory to find the next data point.

As for what Uint8Array is, it's a typed array. Essentially, it tells the compiler/interpreter that you will be accessing this data exclusively as 8-bit uints which, again, allows it to make better optimizations. Then you can use standard array indexing on it (arr[0], arr[1], etc.) and you'll be getting back the equivalent uint values out of the array.

TL;DR They take less space when the exact data format is known, allows you to move more exactly through your data and gives the compiler/interpreter greater options for optimization.

🌐
GeeksforGeeks
geeksforgeeks.org › javascript › what-is-the-difference-between-an-array-and-an-arraybuffer
What is the Difference Between an Array and an ArrayBuffer? - GeeksforGeeks
July 23, 2025 - Example: This illustrates an array ... console.log(fruits[0]); fruits.push("Date"); console.log(fruits); ... An ArrayBuffer is a low-level binary data buffer....
Discussions

webgl - Difference between "buffer" and "array" in OpenGL? - Game Development Stack Exchange
When I read doc on webGL or OpenGL there can be seen some patterns in how names of functions and objects are used. But I can't understand the difference between buffer object and an array. There are "vertex buffer objects", "vertex array objects" and even some kind of "buffer array" or "arraybuffer... More on gamedev.stackexchange.com
🌐 gamedev.stackexchange.com
November 1, 2018
scala - What is the difference between ArrayBuffer and Array - Stack Overflow
I'm new to scala/java and I have troubles getting the difference between those two. By reading the scala doc I understood that ArrayBuffer are made to be interactive (append, insert, prepend, etc)... More on stackoverflow.com
🌐 stackoverflow.com
What is the difference between an ArrayBuffer and a Blob?
They are super handy if you need a generalized buffer of raw data, but the real power behind these guys is that you can create "views" of the underlying data using JavaScript typed arrays. In fact, multiple views can be created from a single ArrayBuffer source. For example, you could create an 8-bit integer array that shares the same ArrayBuffer as an existing 32-bit integer array from the same data. The underlying data remains the same, we just create different ... More on stackoverflow.com
🌐 stackoverflow.com
February 23, 2017
Difference between an ArrayBuffer and a Blob
The ArrayBuffer object is used to represent a generic, fixed-length raw binary data buffer. You cannot directly manipulate the contents of an ArrayBuffer; instead, you create one of the typed array objects or a DataView object which represents the buffer in a specific format, and use that to ... More on github.com
🌐 github.com
0
July 13, 2018
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › ArrayBuffer
ArrayBuffer - JavaScript - MDN Web Docs
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015. * Some parts of this feature may have varying levels of support. ... The ArrayBuffer object is used to represent a generic raw binary data buffer.
🌐
CodeForGeek
codeforgeek.com › home › node.js buffer vs arraybuffer: the senior engineer’s guide to binary data in 2026
Node.js Buffer vs ArrayBuffer: The Senior Engineer's Guide to Binary Data in 2026 | CodeForGeek
April 15, 2026 - The write performance is close but Buffer edges out ArrayBuffer by about 15%. The difference comes from Buffer’s direct memory access versus ArrayBuffer’s view indirection. Copy benchmark (1 MB buffer copy, 100 iterations): ... Again, the ...
🌐
JavaScript.info
javascript.info › tutorial › binary data, files
ArrayBuffer, binary arrays
July 11, 2022 - This allocates a contiguous memory area of 16 bytes and pre-fills it with zeroes. ... Let’s eliminate a possible source of confusion. ArrayBuffer has nothing in common with Array: It has a fixed length, we can’t increase or decrease it. It takes exactly that much space in the memory. To access individual bytes, another “view” object is needed, not buffer[index].
Top answer
1 of 4
7

The naming of Vertex Array Object is somewhat unfortunate. There's three different things that appear (used to appear) in/with/around your application, and which are (have been, historically) named differently, with "array" or "buffer" in the name (well, there's framebuffer objects too, but I'll ignore that).

  1. Data that lives in your application, formally and factually, but which is pulled by OpenGL in one go (as opposed to vertex-by-vertex). This was once upon a time what you would call vertex array.
    The intent of this was to make accessing more efficient since OpenGL could just copy the whole thing in one go at a well-defined time when you gave the promise that data was consistent, and push it over AGP or whatever in one block. This no longer exists.
  2. Data obscured and accessible by a handle that can be "bound", i.e. made active. Data may factually live in main memory, or on the graphics card, or be moved to a PCIe-mappable region, whatever, but either way you formally do not own (even if it is physically in RAM and if the data came from your application) it -- unless you have currently "mapped" it via the corresponding API, getting back a writeable (and sometimes readable) pointer. You are also limited in your ability of controlling what happens to the data at all (you can give some hints, but that's pretty much it).
    OpenGL may move this data around more or less freely, and you are only ever allowed/able to copy to/from the buffer via the corresponding API or access the data while it is being mapped. That is what you call a buffer object (vertex buffer object if it contains vertices, but it really doesn't have to, could as well be image data or uniforms, only vertices were the first to be supported, once upon a time).
    The intent of this is to guarantee that OpenGL can (in principle) do what it wants, it can even push the buffer over PCIe speculatively before you even draw. That works because you do not own the data (OpenGL does!) and you can only access it via the given API, so it is known at all times that data is valid. The driver can even opt to throw away buffer memory on the graphics card when it needs memory for something different and later restore it from its secret copy when needed.
  3. A really stupid misnomer for which a much better name would be something like buffer-set or descriptor-set, this is the infamous vertex array object. It is, from your point of view, nothing but a set of buffer handles bunched together under another obscure handle (which you can bind). As it happens, reality is a bit more complicated. In fact, VAO is much closer to how the actual hardware works. Graphic cards have a small number (often something like 2, 4, or 8) of descriptor sets (not just for buffers, but also for samplers) with so-and-so-many entries in each, between which they can switch very efficiently.
    Now, the intent of the vertex array object is to reduce the number of API calls and to reduce the number of consistency checks that OpenGL must make internally, and of course, to use the hardware as-it-works. If you bind 5 buffers, then each must go through some possibly expensive checks, and each one is a candidate for cache misses in the driver, plus each single one requires communicating with the graphics card to change a descriptor, etc etc. If you instead bind one VAO, the driver can (often) simply switch the descriptor set on the graphics card, and be done.
2 of 4
11

A Vertex Array Object (VAO) is an object which contains one or more Vertex Buffer Objects and is designed to store the information for a complete rendered object.

(pulled from khronos)

Each buffer tends to constitute one attribute of a vertex array (object). A VAO can contain many vertex attributes (e.g. position, color, UV). Each might be held in its own buffer, where buffer indicates an unformatted series of contiguous bytes, and where you need to explicitly specify the size (type) per buffer element for both CPU side OpenGL calls and GPU-side shader work.

That's one way. The other ways this can work are:

  • All of the attributes are stored interleaved in a single buffer, OR
  • Some of the attributes exist in their own dedicated buffers, while others share buffers.

The below diagram illustrates these latter two cases.

Bottom line: If the phrase "vertex array" is used unqualified in OpenGL, you can assume it means VAO, which, in an OpenGL context (specifically) is a very different thing indeed from a buffer.

EDIT re your comment: GL_ARRAY_BUFFER indicates an intention to use that buffer object for vertex attribute data, as described above. This is because buffers are not used only for vertex attributes. However, as it is the most common use-case and you are asking about VAOs, I won't go into the others; here however is a list of the other types of buffers that can be set up.

Top answer
1 of 4
49

Both Array and ArrayBuffer are mutable, which means that you can modify elements at particular indexes: a(i) = e

ArrayBuffer is resizable, Array isn't. If you append an element to an ArrayBuffer, it gets larger. If you try to append an element to an Array, you get a new array. Therefore to use Arrays efficiently, you must know its size beforehand.

Arrays are implemented on JVM level and are the only non-erased generic type. This means that they are the most efficient way to store sequences of objects – no extra memory overhead, and some operations are implemented as single JVM opcodes.

ArrayBuffer is implemented by having an Array internally, and allocating a new one if needed. Appending is usually fast, unless it hits a limit and resizes the array – but it does it in such a way, that the overall effect is negligible, so don't worry. Prepending is implemented as moving all elements to the right and setting the new one as the 0th element and it's therefore slow. Appending n elements in a loop is efficient (O(n)), prepending them is not (O(n²)).

Arrays are specialized for built-in value types (except Unit), so Array[Int] is going to be much more optimal than ArrayBuffer[Int] – the values won't have to be boxed, therefore using less memory and less indirection. Note that the specialization, as always, works only if the type is monomorphic – Array[T] will be always boxed.

2 of 4
4

The one other difference is, Array's element created as on when its declared but Array Buffer's elements not created unless you assign values for the first time.

For example. You can write Array1(0)="Stackoverflow" but not ArrayBuffer1(0)="Stackoverflow" for the first time value assignments.

(Array1 = Array variable & ArrayBuffer1 = ArrayBuffer variable)

Because as we know, Array buffers are re-sizable, so elements created when you insert values at the first time and then you can modify/reassign them at the particular element.

Array:

Declaring and assigning values to Int Array.

val favNums= new ArrayInt

for(i<-0 to 19){
favNums(i)=i*2
}
favNums.foreach(println)

ArrayBuffer:

Declaring and assigning values to Int ArrayBuffer.

val favNumsArrayBuffer= new ArrayBuffer[Int]
    for(j<-0 to 19){
    favNumsArrayBuffer.insert(j, (j*2))
    //favNumsArrayBuffer++=Array(j*3)
      }
    favNumsArrayBuffer.foreach(println)

If you include favNumsArrayBuffer(j)=j*2 at the first line in the for loop, It doesn't work. But it works fine if you declare it in 2nd or 3rd line of the loop. Because values assigned already at the first line now you can modify by element index.

This simple one-hour video tutorial explains a lot.

https://youtu.be/DzFt0YkZo8M?t=2005

🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Typed_arrays
JavaScript typed arrays - JavaScript | MDN
In other words, the two arrays are indeed viewed on the same data buffer, treating it as different formats. Int16Array | 32 | 0 | 2 | 0 | 4 | 0 | 6 | 0 | Int32Array | 32 | 2 | 4 | 6 | ArrayBuffer | 20 00 00 00 | 02 00 00 00 | 04 00 00 00 | 06 00 00 00 | You can do this with any view type, although if you set an integer and then read it as a floating-point number, you will probably get a strange result because the bits are interpreted differently.
Find elsewhere
Top answer
1 of 3
151

Summary

Unless you need the ability to write/edit (using an ArrayBuffer), then Blob format is probably best.

Detail

I came to this question from a different html5rocks page., and I found @Bart van Heukelom's comments to be helpful, so I wanted to elevate them to an answer here.

I also found helpful resources specific to ArrayBuffer and Blob objects. In summary: despite the emphasis on Blob being immutable/"raw data" Blob objects are easy to work with.

Resources that compare / contrast ArrayBuffer vs Blob:

  • Mutability
    • an ArrayBuffer can be changed (e.g. with a DataView)
    • a Blob is immutable
  • Source / Availability in Memory
    • Quoting Bart van Heukelom:
    • An ArrayBuffer is in the memory, available for manipulation.
    • A Blob can be on disk, in cache memory, and other places not readily available
  • Access Layer
    • ArrayBuffer will require some access layer like typed arrays
    • Blob can be passed directly into other functions like window.URL.createObjectURL, as seen in the example from OP's URL.
      • However, as Mörre points out you may still need File-related interfaces and API's like FileReader to work with a Blob.
  • Convert / Generate
    • You can generate Blob from ArrayBuffer and vice versa, which addresses the OP's "Aren't both containers comprised of bits?"
    • ArrayBuffer can be generated from a Blob using the FileReader's readAsArrayBuffer method , or the async method const arrayBuffer = await blob.arrayBuffer() (thanks to @Darren G)
    • Blob can be generated from an ArrayBuffer as @user3405291 points out new Blob([new Uint8Array(data)]);, shown in this answer
  • Use in Other Libraries
    • jsZip; (new JSZip()).loadAsync(...) accepts both ArrayBuffer and Blob: String/Array of bytes/ArrayBuffer/Uint8Array/Buffer/Blob/Promise
  • How does protocol handle ArrayBuffer vs Blob
    • Websocket (aka WS / WSS)
      • Use the webSocket's binaryType property (could have values "arraybuffer" or "blob") to "control the type of binary data being received over the WebSocket connection."
    • XmlHttpRequest (aka XHR)
      • Use the xhr's responseType property to "to change the expected response type from the server" (valid values include "arraybuffer", "blob", and others like "document", "json", and "text")
      • the response property will contain the entity body according to responseType, as an ArrayBuffer, Blob, Document, JSON, or string.

Other helpful documentation:

  • ArrayBuffer

The ArrayBuffer object is used to represent a generic, fixed-length raw binary data buffer. You cannot directly manipulate the contents of an ArrayBuffer; instead, you create one of the typed array objects or a DataView object which represents the buffer in a specific format, and use that to read and write the contents of the buffer.

  • Blob

A Blob object represents a file-like object of immutable, raw data. Blob represent data that isn't necessarily in a JavaScript-native format. The File interface is based on Blob, inheriting blob functionality and expanding it to support files on the user's system.

2 of 3
28

It's explained on the page.

ArrayBuffer

An ArrayBuffer is a generic fixed-length container for binary data. They are super handy if you need a generalized buffer of raw data, but the real power behind these guys is that you can create "views" of the underlying data using JavaScript typed arrays. In fact, multiple views can be created from a single ArrayBuffer source. For example, you could create an 8-bit integer array that shares the same ArrayBuffer as an existing 32-bit integer array from the same data. The underlying data remains the same, we just create different representations of it.

BLOB

If you want to work directly with a Blob and/or don't need to manipulate any of the file's bytes, use xhr.responseType='blob':

🌐
Medium
medium.com › @dev-aditya › buffer-arraybuffer-float64array-in-node-js-ef68c112d905
Buffer, ArrayBuffer, Float64Array in Node.js | by Aditya Yadav | Medium
September 29, 2024 - ... Buffer: Easier methods for string encoding/decoding, etc. ArrayBuffer: More generic, requiring views (Typed Arrays) to manipulate data. Web APIs: Fetching and processing binary data (e.g., images, audio).
🌐
Webdevtutor
webdevtutor.net › blog › javascript-buffer-vs-arraybuffer
JavaScript Buffer vs ArrayBuffer: Understanding the Differences
This can be both advantageous and risky, as it allows for efficient data manipulation but also requires careful handling to avoid unexpected changes. On the other hand, ArrayBuffer is a built-in object in JavaScript that represents a fixed-length raw binary data buffer.
🌐
Medium
medium.com › @conboys111 › arraybuffer-vs-standard-arrays-when-and-why-should-you-use-it-cd2891394fab
ArrayBuffer vs Standard Arrays: When and Why Should You Use It? | by myHotTake | Medium
January 18, 2025 - Efficiency: Instead of creating multiple small bowls (arrays), I use one large tray (buffer), reducing memory overhead. Interoperability: This is especially useful for working with binary data (e.g., from files or network streams). Control: I can manage how memory is used and precisely interpret it. For example, ArrayBuffer is often used when working with Web APIs like fetch for handling binary files or WebSockets for sending/receiving data.
🌐
GitHub
github.com › ythy › blog › issues › 124
Difference between an ArrayBuffer and a Blob · Issue #124 · ythy/blog
July 13, 2018 - To achieve maximum flexibility ... views. A buffer (implemented by the ArrayBuffer object) is an object representing a chunk of data; it has no format to speak of and offers no mechanism for accessing its contents...
Author: ythy
🌐
Webdevtutor
webdevtutor.net › blog › javascript-buffer-arraybuffer
Understanding JavaScript Buffer and ArrayBuffer
On the other hand, ArrayBuffer is a core JavaScript feature that represents a generic, fixed-length raw binary data buffer. Unlike Buffer, ArrayBuffer is not limited to Node.js and can be used in web browsers as well. Here's how you can create and manipulate an ArrayBuffer:
🌐
Reddit
reddit.com › r/node › eli5: file, uint8array, buffer, arraybuffer, bytesarray, blob…
r/node on Reddit: ELI5: File, Uint8Array, Buffer, Arraybuffer, BytesArray, Blob…
December 16, 2021 -

I’m always ending up guessing.. I need to somehow understand. I have no idea what I’m doing when working with files. Just trying stuff until it works. Someone plz ELI5..

My current issue is getting a png file from Firebase storage which gives a “file” which I’m trying to add on a pdf, where the library expects a Uint8Array or Arraybuffer. I’ve been doing similar things before. But end up just guessing my way until it works, and this time.. well it doesn’t work. I guessed it all with no success. I don’t know what I’m doing so I guess I need to actually learn ;)

Top answer
1 of 2
36
A digital system, like a computer works on digital data, thus things which can be represented as digits. Or simpler: Computer sees a bit of numbers and works on them. Also a text is just a long number. Some time ago, one decided to have computers work on binary digits and to group 8 out of those as the typical size. That is a byte. (There were computers using other byte sizes, that's why sometimes, especially in network protocols, it is called octet) With a byte of eight bits you can represent 256 values. (From 0 to 255) over multiple decades there were discussions on representing text (actually that was prr-computer already with telegraphs etc) and one found the ASCII rules to map between numeric values and characters. Each letter in the English alphabet got a code. Thus the word Hello becomes the sequence of numbers 72 101 108 108 111 Now decimal system ia nice when counting with fingers, but not so good for a binary machine. As said we have the byte, thus instead ten digits is inconvenient so we use a number system with base 16, thus any digit can not only have ten different values (0 to 9) but 16 (0 to 9 and A to F) Thus the same numbers as above can be written in hex 0x48 0x65 0x6C 0x6C 0x6F Now each byte is represented by two hex digits which gives a nice structure (and if you notice that 0x41 is A and 0x61 is a you start to understand ASCII) Now over time 256 characters wasn't enough for represting text in all languages, so after many years and messing around with different code pages and encodings smart folks came up with Unicode and Utf-8 to encode all characters. Won't go there too deep, but in essence utf-8 uses the ASCII table for the first 128 characters (half a byte, the lower half) and all other characters use multiple bytes. The German letter Ä fornisntance is 0xC3 0x48. In addition the Unicode standard has specific rules on sorting and comparing those values and some fancy transformations. (Sorting rules are even language dependent, so the German Ä can be sorted like AE, behind Z or simply as A) Wenn Browsers and JavaScript were created it was decided that a string in JavaScirpt shall be Unicode data. This is logical as websites are full of human readable text and properties of Unicode are good (well, the story is more complicated there, but good enough) This was good for the time where Web was working with simple websites and JavaScript was doing minor text manipulation. However for lower layers of the compitong stack data is just a sequence of bytes. In memory you have bytes. A file is a sequence of bytes. The meaning of those bytes might be Unicode text, might be an image, might even be bianry program code all are just bytes. The difference is only in the one looking at it. Now treating all data as unicode string will do harm, as they have all the assumptions on top where only specific byte sequences are valid and so on. So something else had to be added. And in fact different groups added different things. Before we can explain that, one step more is needed: as said interpretation depends on who looks at the data. So back to our numbers and from decimal and hex to binary. As said 8 bit are a byte. The number 1 in binary with it 8 bits would look like 0b00000001 Here using 0b as prefix, so you interpret it as binary, not hey, not decimal. The value 127 inn inary looks like this: 0b01111111 all bits, but the first set. Now something fancy happens when we set the first bit to 1 as well: 0b11111111 This can either be 255 or -1. Wait what negative!? You will ask: Yes, there eisna problem with these numbers: Our byte has to represent negative numbers as well. And then the first digit tells us whether it's negative or positive. And whenever we look at the byte we have to make a choice how we look at it. Is it a text character? Is it a positive number? A negative number? The byte doesn't know and doesn't care only we when looking at it. Now the Uint8Array enters! By giving a sequence of bytes (some area in memory) to an Uint8Buffer we tell it "look at those bytes and treat tit like a sequence of bytes, where each byte is a 8 bit unsigned number" and by that we can work with those.bytes and each byte will be a number 0 to 256 and whatever we do with the array decides on what it does with those bytes. Maybe it is a pixel in an image, maybe an frequency on an audio file, maybe ... Now another term there eisnthe Buffer. A buffer is just some area in memory. An arrayBuffer is "this is my area of memory, but I haven't yet decided how i will interpret it" I said Buffer, I said complicazednhsorory ... That tis that Node.js developers Hand this issue before ArrayBuffer d Uint8Array was defined, so they created their own thing, which is similar to an Unit8Array (modern versions of Buffer are built on Uint8Array) but don't be confused, buffer is a generic term for some data stored somewhere, which is distinct from Buffer, which is a type in Node.js. Now there ris a bit more. 256 is a bit low formmany purposes. So you can group multiple bytes and make them digits in a larger number. Quite typical are efor 4 byte, which are 32 bit. Thus a Int32Array takes 4 bytes at once from the underlying data (the ArrayBuffer, the buffer, the memory region) and makes it a 32 bit signed number (- 2147483648 to 2147483647) the Uint32Array (0 to 4294967295) and if that isn't enought there are big(u)int64Array, which look at 8 byte at a time, which is also the number of byte/bit a modern CPU can store in it's register, transfer though bus and process the best, hence 64bit architecture. The key thing is: memory (RAM, disk or any other form) in modern computers is just a sequence of bytes and the way you look at it decides on the meaning. The computer doesn't know and you have to tell it. Uint8Array is the typically representation for low level work. ArrayBuffer is when you haven't decided, yet and all else are more special.
2 of 2
1
it's a bit of a Pia esp when different libs want diff types. An ArrayBuffer is raw data. Like a big bag of data. You can't do anything with it - but if you convert it to something that can look inside the bag (Uint8Array), you can read / write it. If you just want to read, then Blob is your guy.
Author: nodejs
🌐
Observable
observablehq.com › @julesblm › typed-arrays-and-arraybuffers-too
Typed Arrays and ArrayBuffers / Jules Blom
Observable · Sign in · Typed Arrays and ArrayBuffers | Jules Blom | Observable · Public · Jul 2 · Tinker · •ojs
🌐
C# Corner
c-sharpcorner.com › home › technologies › javascript › arraybuffer vs typed array in javascript
ArrayBuffer vs Typed Array in JavaScript
July 18, 2023 - Shared Memory: Multiple views (Typed Arrays) can be created on a single ArrayBuffer, enabling efficient data sharing and manipulation across different views. Let's have an example to understand the Arraybuffer · const buffer = new ArrayBuffer(20); // Get the byte length of the buffer const byteLength = buffer.byteLength; console.log('Length of ArrayBuffer: '+byteLength); // Manipulate binary data using a DataView const view = new DataView(buffer); view.setUint8(0, 255); // Set the first byte to 255 const value = view.getUint8(0); // Get the value of the first byte console.log('Value of the first byteP: '+value);