--- title: DataView.prototype.getInt32() slug: Web/JavaScript/Reference/Global_Objects/DataView/getInt32 translation_of: Web/JavaScript/Reference/Global_Objects/DataView/getInt32 ---
{{JSRef}}

getInt32()方法DataView相对于起始位置偏移 n 个字节处开始,获取一个32-bit数(长整型,4个字节).

{{EmbedInteractiveExample("pages/js/dataview-getint32.html")}}

语法

dataview.getInt32(byteOffset [, littleEndian])

参数

byteOffset
偏移量, 单位为字节, 从头开始计算.
littleEndian
{{optional_inline}} Indicates whether the 32-bit int is stored in {{Glossary("Endianness", "little- or big-endian")}} format. If false or undefined, a big-endian value is read.

返回

一个长整型32位数.

抛出错误

{{jsxref("RangeError")}}
如果byteOffset超出了视图能储存的值,就会抛出错误.

描述

 没有对齐约束; 多字节值可以从任何偏移量获取.

例子

var buffer = new ArrayBuffer(8);
var dataview = new DataView(buffer);
dataview.getInt32(1); // 0

规范

Specification Status Comment
{{SpecName('Typed Array')}} {{Spec2('Typed Array')}} Superseded by ECMAScript 6.
{{SpecName('ES6', '#sec-dataview.prototype.getint32', 'DataView.prototype.getInt32')}} {{Spec2('ES6')}} Initial definition in an ECMA standard.
{{SpecName('ESDraft', '#sec-dataview.prototype.getint32', 'DataView.prototype.getInt32')}} {{Spec2('ESDraft')}}

浏览器支持

{{Compat("javascript.builtins.DataView.getInt32")}}

另见