<script type="text/javascript">
    var personnel = new Array();

    var personnel[0] = new Array();
    personnel[0][0] = "Name0";
    personnel[0][1] = "Age0";
    personnel[0][2] = "Address0";

    var personnel[1] = new Array();

    personnel[1][0] = "Name1";
    personnel[1][1] = "Age1";
    personnel[1][2] = "Address1";

    document.write("Name:" + personnel[1][0]);
</script>


当它运行到浏览器中时,出现以下错误:


  语法错误:丢失;语句前var personnel[0] = new Array();

最佳答案

var personnel[0] = new Array();是语法错误!
  
  您可以使用[]而不是new Array()清理代码


尝试这个:



var personnel = new Array();

personnel[0] = new Array();
personnel[0][0] = "Name0";
personnel[0][1] = "Age0";
personnel[0][2] = "Address0";

personnel[1] = new Array();

personnel[1][0] = "Name1";
personnel[1][1] = "Age1";
personnel[1][2] = "Address1";

document.write("Name:" + personnel[1][0]);

关于javascript - JavaScript多维数组语法错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33460940/

10-09 06:27