未捕获的TypeError:无法在'中使用'运营商搜索'长度'在...`错误

时间:2017-12-03 06:43:59

标签: javascript jquery

我在一个名为undefined的函数中有一个变量,有时它会像这样:input_array这是一个字符串。

后来,我做......

student_selection_101,student_selection_50,tutoring_agreement

我已完成了一百万次测试和迭代,但我无法避免$.each(input_array, function(index, value) { //do stuff } 错误。

我尝试使用下面的代码让Uncaught TypeError: Cannot use 'in' operator to search for 'length' in...成为对象,以避免这种可怕的错误,但它无法正常工作。我也读过其他答案,说input_array是关键,但我不知道如何使用它或者意味着什么。

JSON.parse()

我很感激这里的任何帮助。

1 个答案:

答案 0 :(得分:-1)

亲爱的朋友,亲爱的朋友,我没有动摇,你在寻找什么,但我希望这有效:

var input_array = ['student_selection_101','student_selection_50','tutoring_agreement'];

var jsonFile = JSON.parse(JSON.stringify(input_array));
jsonFile.forEach(function(index,value){
   console.log(index,value)
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>