Esta traducción está incompleta. Por favor, ayuda a traducir este artículo del inglés.

The subarray() method returns a new TypedArray on the same ArrayBuffer store and with the same element types as for this TypedArray object. The begin offset is inclusive and the end offset is exclusive. TypedArray is one of the typed array types.

Syntax

typedarray.subarray([begin [,end]])

Parameters

begin Optional
Element to begin at. The offset is inclusive. The whole array will be cloned if this value is not specified.
end Optional
Element to end at. The offset is exclusive. If not specified, all elements from the one specified by begin to the end of the array are included in the new view.

Return value

A new TypedArray object.

Description

The range specified by begin and end is clamped to the valid index range for the current array; if the computed length of the new array would be negative, it's clamped to zero. If either begin or end is negative, it refers to an index from the end of the array instead of from the beginning.

Also note that this is creating a new view on the existing buffer; changes to the new object's contents will impact the original object and vice versa.

Examples

Using the subarray method

var buffer = new ArrayBuffer(8);
var uint8 = new Uint8Array(buffer);
uint8.set([1,2,3]);

console.log(uint8); // Uint8Array [ 1, 2, 3, 0, 0, 0, 0, 0 ]

var sub = uint8.subarray(0,4);

console.log(sub);   // Uint8Array [ 1, 2, 3, 0 ]

Specifications

Specification Status Comment
Typed Array Specification Obsolete Superseded by ECMAScript 6.
ECMAScript 2015 (6th Edition, ECMA-262)
La definición de 'TypedArray.prototype.subarray' en esta especificación.
Standard Initial definition in an ECMA standard.
ECMAScript Latest Draft (ECMA-262)
La definición de 'TypedArray.prototype.subarray' en esta especificación.
Draft  

Browser compatibility

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
Soporte básicoChrome Soporte completo 7Edge Soporte completo 14Firefox Soporte completo 4IE Soporte completo 10Opera Soporte completo 11.6Safari Soporte completo 5.1WebView Android Soporte completo 4Chrome Android Soporte completo SiEdge Mobile Soporte completo SiFirefox Android Soporte completo 4Opera Android Soporte completo 11.6Safari iOS Soporte completo 4.2Samsung Internet Android Soporte completo Sinodejs Soporte completo 0.12

Leyenda

Soporte completo  
Soporte completo

See also

Etiquetas y colaboradores del documento

Colaboradores en esta página: BubuAnabelas, SphinxKnight, manuelmonjarrezarias
Última actualización por: BubuAnabelas,