-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
142vip.cn
committed
Dec 11, 2023
1 parent
f458ea9
commit 6b33bf2
Showing
33 changed files
with
1,660 additions
and
835 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// 定义数组 | ||
const students = ['Lisa', 'Tom'] | ||
const keys = students.keys() | ||
|
||
// 遍历keys对象 | ||
let text = '' | ||
for (const x of keys) { | ||
text += x + '---' | ||
} | ||
console.log(text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* 创建学生-年龄关系映射 | ||
* - 存储键值对 | ||
*/ | ||
const studentAgeMap = new Map([ | ||
['Tom', 20], | ||
['Lisa', 18] | ||
]) | ||
|
||
/** | ||
* 往集合中增加映射关系 | ||
*/ | ||
studentAgeMap.set('fairy', 24) | ||
|
||
/** | ||
* 根据映射关键字获取值 | ||
*/ | ||
const age = studentAgeMap.get('fairy') | ||
|
||
|
||
/** | ||
* 返回集合中元素个数 | ||
*/ | ||
const size = studentAgeMap.size | ||
|
||
|
||
/** | ||
* 根据键删除映射关系 | ||
*/ | ||
studentAgeMap.delete('fairy') | ||
/** | ||
* 判断键是否存在 | ||
*/ | ||
studentAgeMap.has('fairy') | ||
|
||
/** | ||
* 清空Map | ||
*/ | ||
studentAgeMap.clear() | ||
|
||
/** | ||
* 判断类型,返回对象object | ||
*/ | ||
const mapType = typeof studentAgeMap | ||
|
||
/** | ||
* 判断实例,返回true | ||
*/ | ||
const isMap = studentAgeMap instanceof Map | ||
|
||
/** | ||
* 循环处理 | ||
*/ | ||
studentAgeMap.forEach((value, key, originMap) => { | ||
console.log(key, value, JSON.stringify(originMap)) | ||
}) | ||
|
||
/** | ||
* 获取所有的键 | ||
*/ | ||
studentAgeMap.keys() | ||
|
||
/** | ||
* 获取所有的键、值 | ||
*/ | ||
studentAgeMap.entries() | ||
|
||
|
||
/** | ||
* 获取所有的值 | ||
*/ | ||
studentAgeMap.values() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* 使用数组创建Set集合 | ||
*/ | ||
const stuSet = new Set([1, 2, 3]) | ||
|
||
/** | ||
* 利用add()方法创建Set集合 | ||
*/ | ||
const studentSet = new Set() | ||
studentSet.add(1) | ||
studentSet.add(2) | ||
studentSet.add(3) | ||
|
||
/** | ||
* 列出集合中所有值 | ||
*/ | ||
let result = '' | ||
studentSet.forEach((value) => { | ||
result += value | ||
}) | ||
console.log(result) | ||
|
||
/** | ||
* Set集合中没有Key的概念 | ||
* keys()方法和values()方法效果一样 | ||
*/ | ||
studentSet.values() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.