2023-Cannot read properties of undefined (reading ‘indexOf‘)

Cannot read properties of undefined (reading ‘indexOf’)

如何处理这个问题

2023-Cannot read properties of undefined (reading ‘indexOf‘)_第1张图片
Error in render: “TypeError: Cannot read properties of undefined (reading ‘indexOf’)” found in

前言

This error occurs when you try to access the 'indexOf' property of an undefined value. In most cases, this occurs when you are attempting to access an array or a string that has not been initialized or has been assigned a value of undefined.

To fix this error, you should check if the object you are attempting to access exists before trying to use it. You can use the typeof operator to determine if a variable is undefined before trying to use it.
 // Example:
let myArray;
if (typeof myArray !== 'undefined' && myArray.indexOf('someValue') !== -1) {
  // do something with myArray
}
 // In this example, we check if myArray exists and has a defined value before trying to use the indexOf method.

1. 首先看看我们的代码是如何写的

2023-Cannot read properties of undefined (reading ‘indexOf‘)_第2张图片
代码是这样子的,看上去视乎是没有错误的,但是控制台是在报错的,那我们如何解决呢???

2. 解决问题

  • 其实这个问题很容易解决的,我们直接上代码吧
    2023-Cannot read properties of undefined (reading ‘indexOf‘)_第3张图片
  • 需要加这个代码,更加严谨才可以!!!!!!!

3. 搞定

2023-Cannot read properties of undefined (reading ‘indexOf‘)_第4张图片

你可能感兴趣的:(数学建模,前端)