Can I convert a Buffer to a Uint8Array in place, or does it always create a new array?

Responsive Ad Header

Question

Grade: Education Subject: Support
Can I convert a Buffer to a Uint8Array in place, or does it always create a new array?
Asked by:
86 Viewed 86 Answers

Answer (86)

Best Answer
(268)
Converting a Buffer to a Uint8Array always creates a new array. The original Buffer remains unchanged. This is because the `Uint8Array` constructor creates a separate copy of the data. If you need to modify the data in place, you'll need to modify the Buffer directly.