Gives an error when entering an empty value into value?

  • 0
    document.getElementById('FN').value = values[1][1] || '';

    if the values ​​array is empty, then an error is generated:
    Uncaught TypeError: Cannot read property '1' of undefined
    what did you do wrong?
    JavaScript Anonymous, Aug 20, 2020

  • 1 Answers
  • 0
    Well, obviously.

    values ​​= []

    hence values ​​[1] = undefined

    You are trying to get the element at index values ​​[1] [1] (undefined [1])

    But undefined doesn't have that. Here comes the mistake.

    Cannot read property '1' of undefined
    Scarlett Butler

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!