js

作者: 余生的记忆 | 来源:发表于2018-06-01 23:35 被阅读0次

**索引数组:下标为数字**

```js

var a=[1,2,3,4,5,6,7,8,9,10];

//给最后一个设置元素

a[a.length]=1;

console.log(a);

```

**遍历:一次输出所有的元素**

```js

for(b=0;b<a.length;b++{

//输出所有元素

console.log(a[b]);

//输出下标

    console.log(b);

}

```

**关联数组/hash数组:下标为关键字**

```js

var tr=[];

tr['hright']='1.7mm';

tr['weight']='100000000t';

tr['sex']='boy?';

console.log(tr);

```

**关联数组没有长度,所以它有别的遍历方法for...in**

```js

for(var a in tr){

    console.log(tr[a]);

}

```

相关文章

网友评论

      本文标题:js

      本文链接:https://www.haomeiwen.com/subject/hdjlsftx.html