The arguments object – JavaScript [closed]

I have ran the below code. But I am supposed to get the minimum number from the data array as -1 but what I am getting is the initialized value of ‘min’ variable i.e 0

let data = [2,3,4,2,6,7,8,9,-1,7,6,4,3]
let  min = 0

function findMin() {

  for (let n of arguments) {
      if(n < min) {
          min = n
      }
  }
  return min
}

const smallNumber = findMin(data)
console.log(smallNumber)

Can someone help to explain ?

Answer

The arguments is an Array-like object that has entries for each argument the function was called with, with the first entry’s index at 0.

Try this snippet

let data = [2, 3, 4, 2, 6, 7, 8, 9, -1, 7, 6, 4, 3];
let min = 0;

function findMin() {
  for (let n of arguments[0]) {
    if (n < min) {
        min = n;
    }
  }
  return min;
}

const smallNumber = findMin(data);
console.log(smallNumber);