# 数组

# 通过修改数组索引新增数组元素

  • 可以通过修改数组索引的方式追加数组元素

    1
    2
    3
    4
    5
    var numbers = [0,1,2,3,4];
    console.log(numbers.length);
    numbers.length = 10;
    console.log(numbers);
    console.log(numbers.length)
  • 新增数组元素

    1
    2
    3
    4
    5
    var numebrs = [0,1,2,3,4];
    console.log(numebrs.length);
    numebrs[8] = 1;
    console.log(numebrs);
    console.log(numebrs.length);