If you've ever used JavaScript's split method, there's a good chance that you've encountered the following error: TypeError: Cannot read property 'split' of undefined.

如果你曾经使用过 JavaScript 的 split 方法,很有可能你遇到了下面的错误: TypeError: Can not read property‘ split’of undefined。

There are a few reasons why you would receive this error. Most likely it's just a basic misunderstanding of how split works and how to iterate through arrays.

您会收到这个错误的原因有几个。很可能这只是对分割如何工作以及如何遍历数组的基本误解。

For example, if you try to submit the following code for the Find the Longest Word in a String challenge:

例如,如果你尝试提交下面的代码来进行查找字符串中最长的单词的挑战:

function findLongestWord(str) {
     
      
  for(let i = 0; i < str.length; i++) {
     
     
    const array = str.split(" ");
    array[i].split("");
  }
}