## for循环
~~~
for(j = 0; j < arr.length; j++) {
}
//其它样式的for循环
for(j = 0,len=arr.length; j < len; j++) {
}
//用临时变量将长度缓存起来,避免重复获取数组长度,性能比for好
for(i = 0; arr[i] != null; i++){
}
//比for性能差
~~~
## forEach 循环 (性能比普通for弱)
```
arr.forEach(function(i){
})
```
## for in (可以遍历对象 ,性能最差)
```
for(j in obj){
}
```
## map遍历(不如forEach高效)
```
arr.map(function(n){
}
```
## forof遍历(需要ES6支持)
```
for(let value of arr) {
}
```

## some filter findIndex
**some 可以通过 return turn终止循环
**
**filter 把符合条件返回到一个新数组
**
**findIndex 找到对应项的索引
**
```
del(id) {
// 在数字中some 方法如果return true,就会立即终止循环
// this.list.some((item,i)=>{
// if(item.id == id){
// this.list.splice(i,1);
// return true;
// };
// // console.log(data.list);
// })
/* findIndex一个方法查索引 */
var index = this.list.findIndex(item => {
if (item.id == id) {
return true;
}
})
console.log(index);
this.list.splice(index, 1);
},
search(keywords) {
var newList = [];
this.list.forEach(item=>{
if (item.name.indexOf(keywords) != -1) {
newList.push(item)
}
})
return newList;
/*
forEach
some 可以通过 return turn终止循环
filter 把符合条件返回到一个新数组
findIndex 找到对应项的索引
*/
// var newList = this.list.filter(item => {
// // if(item.name.indexOf(keywords) != -1)
// // 注意:ES6中,为字符串提供了一个新方法,叫做 String.prototype.includes('要包含的字符串')
// if (item.name.includes(keywords)) {
// return item;
// }
// })
// return newList;
}
}
```
[参考](https://dailc.github.io/2016/11/25/baseKnowlenge_javascript_jsarrayGoThrough.html)
- 面试题
- 自我介绍
- 问答
- HTML
- 1.@import与link的区别
- CSS
- 1.display: none; 与visibiliy: hidden; 的区别
- 三角形
- margin-top
- 移动端适配问题
- JavaScript
- JavaScript原型和原型链
- 什么是promise
- call、apply、bind区别
- 用函数将字符串转化为驼峰命名
- 数组操作
- 1.筛选
- 2.排序
- 3.反转
- 4.去重
- 字符串方法
- 5.二叉树
- 6.克隆数组
- 重载
- (待完善)JavaScript事件
- dom事件流
- 四则运算符
- cookie,LocalStorage,sessionStorage
- 浅拷贝和深拷贝
- 对象
- 浏览器
- web性能优化
- 定时器
- 回调地狱
- 遍历的几种方式
- this指向
- HTTP
- 输入ur发生了什么
- ajax
- 跨域
- jquery跨域
- axios
- vue
- (待完善)缓存
- bootstarp
- es6
- 01解构赋值
- (未完成)class