Monday, November 18, 2024
Google search engine
HomeLanguagesJavascriptJavaScript typedArray.set() Method

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 the typedArray at which to begin setting the values. Its default values is zero (0).

Return value: It returns the new formed typedArray. 

Example: JavaScript code to show the working of this function.

Javascript




// Creating some buffers with sizes in bytes
const buf1 = new ArrayBuffer(8);
const buf2 = new ArrayBuffer(12);
const buf3 = new ArrayBuffer(16);
  
// Creating some typedArray
const A = new Uint8Array(buf1);
const B = new Uint8Array(buf2);
const C = new Uint8Array(buf3);
  
// Copying the values into the array
// starting at index 3, 4, 5
A.set([ 1, 2, 3, 4 ], 3);
B.set([ 1, 2, 3, 5, 6 ], 4);
C.set([ 1, 2 ], 5);
  
// Printing modified values
console.log(A);
console.log(B);
console.log(C);


Output: 

0,0,0,1,2,3,4,0
0,0,0,0,1,2,3,5,6,0,0,0
0,0,0,0,0,1,2,0,0,0,0,0,0,0,0,0
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments