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 info M maha123 Follow Improve Article Tags : JavaScript Web Technologies Geeks Premier League JavaScript-Methods Geeks Premier League 2023 +1 More Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings6 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in Javascript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)9 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readJavascript Scope3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like