我怎么能在Javascript中操作这个数组进行这种错误检查? [英] How could I manipulate this array in Javascript for this kind of error checking?
问题描述
如何让Javascript检查一个数组,并确保在用逗号分隔数组的每个元素后没有提交错误。例如,用户可以形成一个数组,其中一行中有两个逗号分隔元素而不是一个逗号..不只是逗号,任何其他错误的输入。
How can I make Javascript check an array and make sure that there's no error commited after the comma separating each element of the array .. For example a user may form an array with two commas in a row separating an element instead of one comma .. Not just comma , any other wrong input.
var cars=["Saab",,"Volvo","BMW"]; // Here , this array has an error , there's a double comma .
var cars=["Saab",*"Volvo","BMW"]; // this array has an error , there's an axterix.
var cars=["Saab","Volvo","BMW"]; // this array is the right one.
这是错误的数组
什么是javascript我可以使用函数或解决方案来确保检查数组并且没有错误。只有元素和分隔逗号之间没有空格。
What javascript function or solution could I use to make sure an array is checked and no error is within it .. Only elements and separating commas with no space in between.
你的帮助会非常感激。
推荐答案
使用静态代码分析器,例如 JSLint 或 JSHint 。
Use a static code analyzer such as JSLint or JSHint.
后者可以作为JavaScript库使用网络主持的风味。
The latter is available as a JavaScript library in addition to the web-hosted flavor.
这篇关于我怎么能在Javascript中操作这个数组进行这种错误检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!