0

I want to change the values of elements of an array to the same number. For eg:

let arr = [1,2,3]
arr[0] = 0;
arr[1] = 0;
arr[2] = 0;

Is there any other method to do this?

Radu Diță
  • 13,476
  • 2
  • 30
  • 34
Akash C
  • 11
  • does this link help you? https://stackoverflow.com/questions/12503146/create-an-array-with-same-element-repeated-multiple-times – charmian Aug 30 '22 at 05:46

1 Answers1

1

Try Array.fill:

let arr = [1,2,3];
arr.fill(0);
Radu Diță
  • 13,476
  • 2
  • 30
  • 34