我在一个名为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()
我很感激这里的任何帮助。
答案 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>