JavaScript SharedArrayBuffer.prototype.slice() Method Last Updated : 09 Jan, 2024 Comments Improve Suggest changes Like Article Like Report JavaScript SharedArrayBuffer.prototype.slice() method is specifically for the objects of the SharedArrayBuffer type. It is used to create a new SharedArrayBuffer object that references the same memory region as the original but with a different range. Syntax:sharedArrayBufferVariable.slice(start, end);Parameters:start: An optional parameter representing the start index.end: An optional parameter representing the end index. If omitted, the new SharedArrayBuffer will extend to the end of the original buffer.Return Value:It returns a new SharedArrayBuffer object representing the specified portion of the original buffer.Example 1: The code example practically implements the SharedArrayBuffer.prototype.slice() method. JavaScript const buffer = new SharedArrayBuffer(16); const intArray = new Int32Array(buffer); // Fill the array with the some values intArray[0] = 1; intArray[1] = 2; intArray[2] = 3; intArray[3] = 4; // Use the slice() function to // create a new view of SharedArrayBuffer const GFG = intArray.slice(0, 2); console.log("Original Array:", intArray); // Display the new array created // using the slice() console.log("New Array:", GFG); OutputOriginal Array: Int32Array(4) [ 1, 2, 3, 4 ] New Array: Int32Array(2) [ 1, 2 ] Example 2: The below code example also implements the slice() method of SharedArrayBuffer. JavaScript const Buffer = new SharedArrayBuffer(8); const Array = new Uint8Array(Buffer); // Use slice on the TypedArray to create // a new buffer from 2nd to the 5th byte const slicedArray = Array.slice(1, 5); // Create a new SharedArrayBuffer // from sliced TypedArray const slicedBuffer = slicedArray.buffer; console.log(slicedBuffer.byteLength); Output4 Comment More infoAdvertise with us Next Article JavaScript SharedArrayBuffer.prototype.slice() Method M maha123 Follow Improve Article Tags : JavaScript Web Technologies Geeks Premier League JavaScript-Methods Geeks Premier League 2023 +1 More Similar Reads JavaScript typedArray.set() Method The typedArray.set() is an inbuilt function in JavaScript which is used to stores a number of values in the given typedArray. typedArray.set(typedArray, offset) Parameters: It accept two parameters which are specified below- typedarray: It is the source array. offset: It is optional and it is into t 1 min read JavaScript ArrayBuffer.prototype.transfer() Method The transfer() method of ArrayBuffer create a new ArrayBuffer that has the same byte content as the current buffer, then detach this current buffer, this means that merely the fresh buffer is able to get at the buried data and not any else. Such an option as transfer() comes in handy when there is a 2 min read JavaScript typedArray.slice() Method The typedArray.slice() is an inbuilt function in JavaScript which is used to return the part of the elements of the given typedArray. typedArray.slice(begin, end) Parameters: It takes two parameter which are specified below- begin: It is the beginning index and it can be negative too.end: It is the 2 min read JavaScript typedArray.from() Property The typedArray.from() is an inbuilt function in JavaScript which is used to construct a new typedArray from a normal array or any iterable object. List of different typedArrays are specified in the table below: Int8Array();Int16Array();Uint32Array();Uint8Array();Uint16Array();Float32Array();Uint8Cla 2 min read JavaScript typedArray.byteOffset Property The typedArray.byteOffset is an inbuilt property in JavaScript that is used to return the offset in bytes of a given typedArray from the start of its ArrayBuffer. Syntax: typedArray.byteOffset Parameter: It does not accept any parameter because it is a property, not a function. Return value: It retu 1 min read Like