JavaScript TypedArray set() Method

The set method in JavaScript is utilized to insert values into the specified array.

Syntax:

Example

array.set(array, Index(Offset) )

Parameters:

It takes in two arguments, which are detailed below.

Array: The source array from which values will be duplicated. All elements from the originating array are transferred into the destination array.

Index (Offset): This specifies the starting position for writing values from the source array. This parameter is optional, and if not provided, the default value is set to (0).

Return value:

A new updated array.

Browser Support:

Chrome 7.0
Safari 5.1
Firefox 4.0
Opera 11.6

Example

JavaScript TypedArray set Method

Example

// JavaScript to illustrate set() method

// Creating some buffers with sizes in bytes

  var buffer1 = new ArrayBuffer(8);

// Creating some typedArray

  var A = new Uint8Array(buffer1);

// Coping the values into the array

  // starting at index 2

A.set([ 1, 2, 3, 4],2);

// Priniting modified values

document.write(A +"<br>");

// expected output:0,0,1,2,3,4,0,0

</script>

Output:

Output

0,0,1,2,3,4,0,0

Input Required

This code uses input(). Please provide values below: