小胖墩er 小胖墩er
首页
  • 前端文章

    • JavaScript
    • Vue
    • ES6
    • Git
  • Vue
  • React
  • HTML
  • CSS
  • 工具类
  • GitHub技巧
  • 博客搭建
  • 友情链接
💖关于
💻收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

小胖墩er

Better later than never.
首页
  • 前端文章

    • JavaScript
    • Vue
    • ES6
    • Git
  • Vue
  • React
  • HTML
  • CSS
  • 工具类
  • GitHub技巧
  • 博客搭建
  • 友情链接
💖关于
💻收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 工具类

  • 问题技巧以及优化

    • 问题总结

    • 优化技巧

      • axios发送get请求url传递字符时需要进行编码
      • 当选择某一项时,需要把指定项的值存储起来后使用
      • 优化&运算
      • 优化if语句中相同的代码案例
      • 解决v-for和v-if不能同时使用问题
      • 优化从两个数组中循环判断相等取值操作
  • 博客搭建

  • GitHub技巧

  • 技术
  • 问题技巧以及优化
  • 优化技巧
小胖墩er
2021-10-21

优化从两个数组中循环判断相等取值操作

data() {
	return {
  	checkBoxList: [
        {
          label: '1',
          name: 'one'
        },
        {
          label: '2',
          name: 'two'
        },
        {
          label: '3',
          name: 'three'
        }
      ],
      checkListTwo: [
        'one', 'two', 'three'
      ]
  }
}

// for循环
const names = []
for (let i = 0; i < this.checkBoxList.length; i++) {
  for (let j = 0; j < this.checkListTwo.length; j++) {
    if (this.checkBoxList[i].name == this.checkListTwo[j]) {
      names.push(this.checkBoxList[i].name)
    }
  }
}

console.log('names ==> ', names); // ["one", "two", "three"]


// 优化
const names1 = this.checkBoxList.filter(item => this.checkListTwo.includes(item.name)).map(item =>item.name)
console.log('names1 ==> ', names1); // ["one", "two", "three"]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
在线编辑 (opens new window)
#技巧总结
上次更新: 2021/11/14, 07:48:46
解决v-for和v-if不能同时使用问题
解决百度无法收录搭建在GitHub上的个人博客的问题

← 解决v-for和v-if不能同时使用问题 解决百度无法收录搭建在GitHub上的个人博客的问题→

最近更新
01
毛玻璃效果
11-23
02
svg基本绘制
11-23
03
滑动登录界面
11-23
更多文章>
🖥️

© 2021 小胖墩er 💌 粤ICP备2021158933号 🛀 Theme by 💝 Vdoing

  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
×