let other = null
console.log(other?.[0]) // undefined

You can use optional chaining to access elements in an array. If the array is null or undefined, attempting to access an element with optional chaining prevents an error from being thrown, returning undefined instead.

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-05-20
  • 2022-02-17
  • 2022-12-23
  • 2022-01-12
  • 2022-12-23
  • 2021-11-09
猜你喜欢
  • 2022-12-23
  • 2021-08-24
  • 2022-12-23
  • 2022-12-23
  • 2021-06-08
  • 2022-01-03
  • 2021-09-10
相关资源
相似解决方案