--- title: DataView slug: Web/JavaScript/Reference/Global_Objects/DataView translation_of: Web/JavaScript/Reference/Global_Objects/DataView original_slug: Web/JavaScript/Referencje/Obiekty/DataView ---
DataView udostępnia niskopoziowy interfejs do zapisu i odczytu typów numerycznych w formie {{jsxref("ArrayBuffer")}} niezależnie od kodowania platformy.
new DataView(buffer [, byteOffset [, byteLength]])
bufferDataView .byteOffset {{optional_inline}}byteLength {{optional_inline}}A new DataView object representing the specified data buffer.
{{jsxref("RangeError")}}byteOffset and byteLength result in the specified view extending past the end of the buffer.Multi-byte number formats are represented in memory differently depending on machine architecture, see {{Glossary("Endianness")}} for an explanation. DataView accessors provide explicit control of how data will be accessed irrespective of the platform architecture's endianness.
var littleEndian = (function() {
var buffer = new ArrayBuffer(2);
new DataView(buffer).setInt16(0, 256, true /* littleEndian */);
// Int16Array uses the platform's endianness.
return new Int16Array(buffer)[0] === 256;
})();
console.log(littleEndian); // true or false
All DataView instances inherit from {{jsxref("DataView.prototype")}} and allows the addition of properties to all DataView objects.
{{page('en-US/Web/JavaScript/Reference/Global_Objects/DataView/prototype','Properties')}}
{{page('en-US/Web/JavaScript/Reference/Global_Objects/DataView/prototype','Methods')}}
var buffer = new ArrayBuffer(16); var dv = new DataView(buffer, 0); dv.setInt16(1, 42); dv.getInt16(1); //42
| Specification | Status | Comment |
|---|---|---|
| {{SpecName('Typed Array')}} | {{Spec2('Typed Array')}} | Superseded by ECMAScript 6 |
| {{SpecName('ES6', '#sec-dataview-constructor', 'DataView')}} | {{Spec2('ES6')}} | Initial definition in an ECMA standard |
| {{SpecName('ESDraft', '#sec-dataview-constructor', 'DataView')}} | {{Spec2('ESDraft')}} |
{{Compat("javascript.builtins.DataView")}}
Starting with Firefox 40, DataView requires to be constructed with a {{jsxref("Operators/new", "new")}} operator. Calling DataView() as a function without new, will throw a {{jsxref("TypeError")}} from now on.
var dv = DataView(buffer, 0); // TypeError: calling a builtin DataView constructor without new is forbidden
var dv = new DataView(buffer, 0);
DataView API to all browsers and Node.js.