我怎么能在Javascript中操作这个数组进行这种错误检查? [英] How could I manipulate this array in Javascript for this kind of error checking?

查看:81
本文介绍了我怎么能在Javascript中操作这个数组进行这种错误检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆