2019年有哪些现代JavaScript代码编写的实用小技巧总结?

更新于
2026-09-30 23:27:20
0阅读来源:SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计1438个文字,预计阅读时间需要6分钟。

2019年有哪些现代JavaScript代码编写的实用小技巧总结?

内容基本是关于从其他大神的文章学习到的东西,以下是对其的简写:

内容主要涉及今年从大神文章中学到的各种东西。分享给家人:Array.includes与条件判断,一般我们判断或用||/条件函数test(fruit) { if (fruit==='apple' || fruit==='strawberry') { console.log(“)} }”

内容基本是今年从其他大神的文章学习到的东西。分享给大家:

1 Array.includes 与条件判断

一般我们判断或用 ||

// condition function test(fruit) { if (fruit == "apple" || fruit == "strawberry") { console.log("red"); } }

如果我们有更多水果

function test(fruit) { const redFruits = ["apple", "strawberry", "cherry", "cranberries"]; if (redFruits.includes(fruit)) { console.log("red"); } }

2 Set 与去重

ES6 提供了新的数据结构 Set。它类似于数组,但是成员的值都是唯一的,没有重复的值。Set 本身是一个构造函数,用来生成 Set 数据结构。

阅读全文
标签:5

本文共计1438个文字,预计阅读时间需要6分钟。

2019年有哪些现代JavaScript代码编写的实用小技巧总结?

内容基本是关于从其他大神的文章学习到的东西,以下是对其的简写:

内容主要涉及今年从大神文章中学到的各种东西。分享给家人:Array.includes与条件判断,一般我们判断或用||/条件函数test(fruit) { if (fruit==='apple' || fruit==='strawberry') { console.log(“)} }”

内容基本是今年从其他大神的文章学习到的东西。分享给大家:

1 Array.includes 与条件判断

一般我们判断或用 ||

// condition function test(fruit) { if (fruit == "apple" || fruit == "strawberry") { console.log("red"); } }

如果我们有更多水果

function test(fruit) { const redFruits = ["apple", "strawberry", "cherry", "cranberries"]; if (redFruits.includes(fruit)) { console.log("red"); } }

2 Set 与去重

ES6 提供了新的数据结构 Set。它类似于数组,但是成员的值都是唯一的,没有重复的值。Set 本身是一个构造函数,用来生成 Set 数据结构。

阅读全文
标签:5