mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-12-17 08:26:32 +08:00
语法高亮,滚动条美化,设置页面调整
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
<div><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/set-prototype-constructor.html" width="100%"></iframe></div>
|
||||
<p class="hidden">The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a class="external" href="https://github.com/mdn/interactive-examples" rel="noopener">https://github.com/mdn/interactive-examples</a> and send us a pull request.</p>
|
||||
<h2 id="语法">语法</h2>
|
||||
<pre class="syntaxbox">new Set([iterable]);</pre>
|
||||
<pre><code class="language-javascript">new Set([iterable]);</code></pre>
|
||||
<h3 id="参数">参数</h3>
|
||||
<dl>
|
||||
<dt>iterable</dt>
|
||||
@@ -58,7 +58,7 @@
|
||||
</dl><p></p>
|
||||
<h2 id="示例">示例</h2>
|
||||
<h3 id="使用Set对象">使用<code>Set</code>对象</h3>
|
||||
<pre class="brush: js">let mySet = new Set();
|
||||
<pre><code class="language-javascript">let mySet = new Set();
|
||||
|
||||
mySet.add(1); // Set(1) {1}
|
||||
mySet.add(5); // Set(2) {1, 5}
|
||||
@@ -82,9 +82,9 @@ mySet.delete(5); // true, 从set中移除5
|
||||
mySet.has(5); // false, 5已经被移除
|
||||
|
||||
mySet.size; // 4, 刚刚移除一个值
|
||||
console.log(mySet); // Set {1, "some text", Object {a: 1, b: 2}, Object {a: 1, b: 2}}</pre>
|
||||
console.log(mySet); // Set {1, "some text", Object {a: 1, b: 2}, Object {a: 1, b: 2}}</code></pre>
|
||||
<h3 id="迭代Set">迭代Set</h3>
|
||||
<pre class="brush: js">// 迭代整个set
|
||||
<pre><code class="language-javascript">// 迭代整个set
|
||||
// 按顺序输出:1, "some text"
|
||||
for (let item of mySet) console.log(item);
|
||||
|
||||
@@ -125,9 +125,9 @@ mySet.forEach(function(value) {
|
||||
// 2
|
||||
// 3
|
||||
// 4
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h3 id="实现基本集合操作">实现基本集合操作</h3>
|
||||
<pre class="brush: js">function isSuperset(set, subset) {
|
||||
<pre><code class="language-javascript">function isSuperset(set, subset) {
|
||||
for (var elem of subset) {
|
||||
if (!set.has(elem)) {
|
||||
return false;
|
||||
@@ -171,9 +171,9 @@ isSuperset(setA, setB); // => true
|
||||
union(setA, setC); // => Set [1, 2, 3, 4, 5, 6]
|
||||
intersection(setA, setC); // => Set [3, 4]
|
||||
difference(setA, setC); // => Set [1, 2]
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h3 id="Array_相关"> <code>Array</code> 相关</h3>
|
||||
<pre class="brush: js">var myArray = ["value1", "value2", "value3"];
|
||||
<pre><code class="language-javascript">var myArray = ["value1", "value2", "value3"];
|
||||
|
||||
// 用Set构造器将Array转换为Set
|
||||
var mySet = new Set(myArray);
|
||||
@@ -181,19 +181,19 @@ var mySet = new Set(myArray);
|
||||
mySet.has("value1"); // returns true
|
||||
|
||||
// 用...(展开操作符)操作符将Set转换为Array
|
||||
console.log([...mySet]); // 与myArray完全一致</pre>
|
||||
console.log([...mySet]); // 与myArray完全一致</code></pre>
|
||||
<h3 id="String_相关"><code>String</code> 相关</h3>
|
||||
<pre class="brush: js">var text = 'Indiana';
|
||||
<pre><code class="language-javascript">var text = 'Indiana';
|
||||
|
||||
var mySet = new Set(text); // Set {'I', 'n', 'd', 'i', 'a'}
|
||||
mySet.size; // 5
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h3 id="数组去重">数组去重</h3>
|
||||
<pre class="brush: js">// Use to remove duplicate elements from the array
|
||||
<pre><code class="language-javascript">// Use to remove duplicate elements from the array
|
||||
const numbers = [2,3,4,4,2,3,3,4,4,5,5,6,6,7,5,32,3,4,5]
|
||||
console.log([...new Set(numbers)])
|
||||
// [2, 3, 4, 5, 6, 7, 32]
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h2 id="规范">规范</h2>
|
||||
<table class="standard-table">
|
||||
<tbody>
|
||||
|
||||
Reference in New Issue
Block a user