Error with charAt()

I keep getting an error that says .charAt is not a function and I’m not sure what the issue is.

const validateCred = array => {
  let nCheck = 0;
  let bEven = false;

  for (let n = array.length -1; n >= 0; n--) {
     cDigit = array.charAt(n),
    nDigit = parseInt(cDigit, 10);

    if (bEven && (nDigit *= 2) > 9) nDigit -= 9;

    nCheck += nDigit;
    bEven = !bEven;
  }

  return (nCheck % 10) == 0;

}

charAt() only works with strings. You probably have an array instead. So array[n] does the trick.

1 Like