{"id":229,"date":"2026-03-07T23:51:52","date_gmt":"2026-03-07T15:51:52","guid":{"rendered":"https:\/\/www.resilence.cn\/?p=229"},"modified":"2026-03-07T23:51:52","modified_gmt":"2026-03-07T15:51:52","slug":"day-6-%e6%95%b0%e7%bb%84%e4%b8%8e%e5%af%b9%e8%b1%a1","status":"publish","type":"post","link":"https:\/\/www.resilence.cn\/?p=229","title":{"rendered":"Day-6-\u6570\u7ec4\u4e0e\u5bf9\u8c61"},"content":{"rendered":"<h1>Day 6: \u6570\u7ec4\u4e0e\u5bf9\u8c61<\/h1>\n<h2>\ud83c\udfaf \u5b66\u4e60\u76ee\u6807<\/h2>\n<ul>\n<li>\u6df1\u5165\u7406\u89e3\u6570\u7ec4\u7684\u64cd\u4f5c\u548c\u5e38\u7528\u65b9\u6cd5<\/li>\n<li>\u638c\u63e1\u5bf9\u8c61\u7684\u521b\u5efa\u3001\u8bbf\u95ee\u548c\u64cd\u4f5c<\/li>\n<li>\u5b66\u4f1a\u4f7f\u7528\u6570\u7ec4\u548c\u5bf9\u8c61\u7684\u9ad8\u7ea7\u7279\u6027<\/li>\n<li>\u7406\u89e3\u5f15\u7528\u7c7b\u578b\u7684\u5de5\u4f5c\u539f\u7406<\/li>\n<\/ul>\n<h2>\ud83d\udca1 \u6838\u5fc3\u6982\u5ff5<\/h2>\n<h3>\u4ec0\u4e48\u662f\u6570\u7ec4\uff1f<\/h3>\n<p>\u6570\u7ec4\u662f\u6709\u5e8f\u7684\u6570\u636e\u96c6\u5408\uff0c\u53ef\u4ee5\u5b58\u50a8\u591a\u4e2a\u503c\u3002\u60f3\u8c61\u6210\u4e00\u8f86\u706b\u8f66\uff0c\u6bcf\u8282\u8f66\u53a2\uff08\u7d22\u5f15\uff09\u88c5\u7740\u4e00\u4e2a\u4e58\u5ba2\uff08\u503c\uff09\u3002<\/p>\n<pre><code class=\"language-javascript\">\/\/ \u521b\u5efa\u6570\u7ec4\nlet fruits = [&quot;\u82f9\u679c&quot;, &quot;\u9999\u8549&quot;, &quot;\u6a59\u5b50&quot;];\nlet numbers = [1, 2, 3, 4, 5];\nlet mixed = [1, &quot;\u4f60\u597d&quot;, true, null];\n<\/code><\/pre>\n<h3>\u4ec0\u4e48\u662f\u5bf9\u8c61\uff1f<\/h3>\n<p>\u5bf9\u8c61\u662f\u65e0\u5e8f\u7684\u952e\u503c\u5bf9\u96c6\u5408\u3002\u60f3\u8c61\u6210\u4e00\u4e2a\u6863\u6848\u67dc\uff0c\u6bcf\u4e2a\u6587\u4ef6\u5939\uff08\u5c5e\u6027\uff09\u90fd\u8d34\u7740\u6807\u7b7e\uff08\u952e\uff09\u3002<\/p>\n<pre><code class=\"language-javascript\">\/\/ \u521b\u5efa\u5bf9\u8c61\nlet person = {\n    name: &quot;\u5f20\u4e09&quot;,\n    age: 25,\n    city: &quot;\u5317\u4eac&quot;\n};\n<\/code><\/pre>\n<h2>\ud83d\udcda \u6570\u7ec4\u8be6\u89e3<\/h2>\n<h3>1. \u521b\u5efa\u6570\u7ec4<\/h3>\n<pre><code class=\"language-javascript\">\/\/ \u5b57\u9762\u91cf\u65b9\u5f0f\uff08\u63a8\u8350\uff09\nlet arr1 = [1, 2, 3];\n\n\/\/ \u6784\u9020\u51fd\u6570\nlet arr2 = new Array(1, 2, 3);\n\n\/\/ \u521b\u5efa\u7a7a\u6570\u7ec4\nlet arr3 = [];\nlet arr4 = new Array();\n\n\/\/ \u521b\u5efa\u6307\u5b9a\u957f\u5ea6\u7684\u6570\u7ec4\nlet arr5 = new Array(5);  \/\/ [empty \u00d7 5]\n<\/code><\/pre>\n<h3>2. \u8bbf\u95ee\u548c\u4fee\u6539\u6570\u7ec4\u5143\u7d20<\/h3>\n<pre><code class=\"language-javascript\">let colors = [&quot;\u7ea2&quot;, &quot;\u7eff&quot;, &quot;\u84dd&quot;];\n\n\/\/ \u8bbf\u95ee\u5143\u7d20\uff08\u7d22\u5f15\u4ece0\u5f00\u59cb\uff09\nconsole.log(colors[0]);  \/\/ &quot;\u7ea2&quot;\nconsole.log(colors[1]);  \/\/ &quot;\u7eff&quot;\n\n\/\/ \u4fee\u6539\u5143\u7d20\ncolors[0] = &quot;\u6a59\u8272&quot;;\nconsole.log(colors);  \/\/ [&quot;\u6a59\u8272&quot;, &quot;\u7eff&quot;, &quot;\u84dd&quot;]\n\n\/\/ \u83b7\u53d6\u6570\u7ec4\u957f\u5ea6\nconsole.log(colors.length);  \/\/ 3\n<\/code><\/pre>\n<h3>3. \u6570\u7ec4\u5e38\u7528\u65b9\u6cd5<\/h3>\n<h4>\u6dfb\u52a0\u5143\u7d20<\/h4>\n<pre><code class=\"language-javascript\">let arr = [1, 2, 3];\n\n\/\/ push() - \u5728\u672b\u5c3e\u6dfb\u52a0\narr.push(4);           \/\/ [1, 2, 3, 4]\narr.push(5, 6);        \/\/ [1, 2, 3, 4, 5, 6]\n\n\/\/ unshift() - \u5728\u5f00\u5934\u6dfb\u52a0\narr.unshift(0);        \/\/ [0, 1, 2, 3, 4, 5, 6]\n\n\/\/ splice() - \u5728\u6307\u5b9a\u4f4d\u7f6e\u6dfb\u52a0\narr.splice(3, 0, 3.5); \/\/ [0, 1, 2, 3.5, 3, 4, 5, 6]\n<\/code><\/pre>\n<h4>\u5220\u9664\u5143\u7d20<\/h4>\n<pre><code class=\"language-javascript\">let arr = [1, 2, 3, 4, 5];\n\n\/\/ pop() - \u5220\u9664\u672b\u5c3e\nlet last = arr.pop();   \/\/ \u8fd4\u56de 5, arr = [1, 2, 3, 4]\n\n\/\/ shift() - \u5220\u9664\u5f00\u5934\nlet first = arr.shift(); \/\/ \u8fd4\u56de 1, arr = [2, 3, 4]\n\n\/\/ splice() - \u5220\u9664\u6307\u5b9a\u4f4d\u7f6e\narr.splice(1, 1);       \/\/ \u5220\u9664\u7d22\u5f151\u76841\u4e2a\u5143\u7d20, arr = [2, 4]\n<\/code><\/pre>\n<h4>\u67e5\u627e\u5143\u7d20<\/h4>\n<pre><code class=\"language-javascript\">let fruits = [&quot;\u82f9\u679c&quot;, &quot;\u9999\u8549&quot;, &quot;\u6a59\u5b50&quot;, &quot;\u82f9\u679c&quot;];\n\n\/\/ indexOf() - \u67e5\u627e\u7d22\u5f15\nconsole.log(fruits.indexOf(&quot;\u9999\u8549&quot;));  \/\/ 1\nconsole.log(fruits.indexOf(&quot;\u8461\u8404&quot;));  \/\/ -1\uff08\u672a\u627e\u5230\uff09\n\n\/\/ lastIndexOf() - \u6700\u540e\u4e00\u6b21\u51fa\u73b0\u7684\u4f4d\u7f6e\nconsole.log(fruits.lastIndexOf(&quot;\u82f9\u679c&quot;)); \/\/ 3\n\n\/\/ includes() - \u662f\u5426\u5305\u542b\nconsole.log(fruits.includes(&quot;\u6a59\u5b50&quot;)); \/\/ true\nconsole.log(fruits.includes(&quot;\u8461\u8404&quot;)); \/\/ false\n\n\/\/ find() - \u67e5\u627e\u7b26\u5408\u6761\u4ef6\u7684\u5143\u7d20\nlet numbers = [1, 2, 3, 4, 5];\nlet found = numbers.find(num =&gt; num &gt; 3); \/\/ 4\n\n\/\/ findIndex() - \u67e5\u627e\u7b26\u5408\u6761\u4ef6\u7684\u7d22\u5f15\nlet index = numbers.findIndex(num =&gt; num &gt; 3); \/\/ 3\n<\/code><\/pre>\n<h4>\u904d\u5386\u6570\u7ec4<\/h4>\n<pre><code class=\"language-javascript\">let numbers = [1, 2, 3, 4, 5];\n\n\/\/ forEach() - \u904d\u5386\u6bcf\u4e2a\u5143\u7d20\nnumbers.forEach((num, index) =&gt; {\n    console.log(`\u7d22\u5f15${index}: ${num}`);\n});\n\n\/\/ map() - \u8f6c\u6362\u6570\u7ec4\uff0c\u8fd4\u56de\u65b0\u6570\u7ec4\nlet doubled = numbers.map(num =&gt; num * 2); \/\/ [2, 4, 6, 8, 10]\n\n\/\/ filter() - \u8fc7\u6ee4\u6570\u7ec4\uff0c\u8fd4\u56de\u65b0\u6570\u7ec4\nlet evens = numbers.filter(num =&gt; num % 2 === 0); \/\/ [2, 4]\n\n\/\/ reduce() - \u7d2f\u8ba1\u8ba1\u7b97\nlet sum = numbers.reduce((total, num) =&gt; total + num, 0); \/\/ 15\n\n\/\/ some() - \u662f\u5426\u6709\u7b26\u5408\u6761\u4ef6\u7684\u5143\u7d20\nlet hasEven = numbers.some(num =&gt; num % 2 === 0); \/\/ true\n\n\/\/ every() - \u662f\u5426\u6240\u6709\u5143\u7d20\u90fd\u7b26\u5408\u6761\u4ef6\nlet allPositive = numbers.every(num =&gt; num &gt; 0); \/\/ true\n<\/code><\/pre>\n<h4>\u6392\u5e8f<\/h4>\n<pre><code class=\"language-javascript\">let arr = [3, 1, 4, 1, 5, 9];\n\n\/\/ sort() - \u6392\u5e8f\uff08\u9ed8\u8ba4\u6309\u5b57\u7b26\u4e32\u6392\u5e8f\uff09\narr.sort();  \/\/ [1, 1, 3, 4, 5, 9]\n\n\/\/ \u6570\u5b57\u6392\u5e8f\narr.sort((a, b) =&gt; a - b);  \/\/ \u5347\u5e8f\narr.sort((a, b) =&gt; b - a);  \/\/ \u964d\u5e8f\n\n\/\/ reverse() - \u53cd\u8f6c\narr.reverse(); \/\/ [9, 5, 4, 3, 1, 1]\n<\/code><\/pre>\n<h4>\u5176\u4ed6\u65b9\u6cd5<\/h4>\n<pre><code class=\"language-javascript\">\/\/ join() - \u8f6c\u4e3a\u5b57\u7b26\u4e32\nlet arr = [1, 2, 3];\nconsole.log(arr.join(&quot;-&quot;));  \/\/ &quot;1-2-3&quot;\nconsole.log(arr.join());     \/\/ &quot;1,2,3&quot;\n\n\/\/ slice() - \u622a\u53d6\u6570\u7ec4\uff08\u4e0d\u4fee\u6539\u539f\u6570\u7ec4\uff09\nlet arr = [1, 2, 3, 4, 5];\nlet sliced = arr.slice(1, 3); \/\/ [2, 3]\n\n\/\/ concat() - \u5408\u5e76\u6570\u7ec4\nlet arr1 = [1, 2];\nlet arr2 = [3, 4];\nlet merged = arr1.concat(arr2); \/\/ [1, 2, 3, 4]\n\n\/\/ spread(...) - \u5c55\u5f00\u6570\u7ec4\nlet arr = [1, 2, 3];\nlet newArr = [...arr, 4, 5]; \/\/ [1, 2, 3, 4, 5]\n<\/code><\/pre>\n<h2>\ud83d\uddc2\ufe0f \u5bf9\u8c61\u8be6\u89e3<\/h2>\n<h3>1. \u521b\u5efa\u5bf9\u8c61<\/h3>\n<pre><code class=\"language-javascript\">\/\/ \u5b57\u9762\u91cf\u65b9\u5f0f\uff08\u63a8\u8350\uff09\nlet person = {\n    name: &quot;\u5f20\u4e09&quot;,\n    age: 25\n};\n\n\/\/ \u6784\u9020\u51fd\u6570\nlet obj = new Object();\nobj.name = &quot;\u674e\u56db&quot;;\nobj.age = 30;\n\n\/\/ Object.create()\nlet proto = { greet: function() { return &quot;Hello&quot;; } };\nlet obj = Object.create(proto);\n<\/code><\/pre>\n<h3>2. \u8bbf\u95ee\u5bf9\u8c61\u5c5e\u6027<\/h3>\n<pre><code class=\"language-javascript\">let person = {\n    name: &quot;\u5f20\u4e09&quot;,\n    age: 25,\n    &quot;full name&quot;: &quot;\u5f20 \u4e09&quot;  \/\/ \u5e26\u7a7a\u683c\u7684\u5c5e\u6027\u540d\n};\n\n\/\/ \u70b9\u8868\u793a\u6cd5\nconsole.log(person.name);  \/\/ &quot;\u5f20\u4e09&quot;\n\n\/\/ \u65b9\u62ec\u53f7\u8868\u793a\u6cd5\nconsole.log(person[&quot;age&quot;]);  \/\/ 25\nconsole.log(person[&quot;full name&quot;]); \/\/ &quot;\u5f20 \u4e09&quot;\uff08\u5fc5\u987b\u7528\u65b9\u62ec\u53f7\uff09\n\n\/\/ \u52a8\u6001\u8bbf\u95ee\nlet key = &quot;name&quot;;\nconsole.log(person[key]);  \/\/ &quot;\u5f20\u4e09&quot;\n<\/code><\/pre>\n<h3>3. \u6dfb\u52a0\u548c\u4fee\u6539\u5c5e\u6027<\/h3>\n<pre><code class=\"language-javascript\">let person = { name: &quot;\u5f20\u4e09&quot; };\n\n\/\/ \u6dfb\u52a0\u5c5e\u6027\nperson.age = 25;\nperson.city = &quot;\u5317\u4eac&quot;;\n\n\/\/ \u4fee\u6539\u5c5e\u6027\nperson.name = &quot;\u674e\u56db&quot;;\n\n\/\/ \u65b9\u62ec\u53f7\u65b9\u5f0f\nperson[&quot;email&quot;] = &quot;test@example.com&quot;;\n<\/code><\/pre>\n<h3>4. \u5220\u9664\u5c5e\u6027<\/h3>\n<pre><code class=\"language-javascript\">let person = {\n    name: &quot;\u5f20\u4e09&quot;,\n    age: 25,\n    city: &quot;\u5317\u4eac&quot;\n};\n\ndelete person.age;\ndelete person[&quot;city&quot;];\nconsole.log(person); \/\/ {name: &quot;\u5f20\u4e09&quot;}\n<\/code><\/pre>\n<h3>5. \u5bf9\u8c61\u65b9\u6cd5<\/h3>\n<pre><code class=\"language-javascript\">let calculator = {\n    add: function(a, b) {\n        return a + b;\n    },\n    \n    subtract(a, b) {\n        return a - b;\n    }\n};\n\nconsole.log(calculator.add(5, 3));      \/\/ 8\nconsole.log(calculator.subtract(5, 3)); \/\/ 2\n<\/code><\/pre>\n<h3>6. \u904d\u5386\u5bf9\u8c61<\/h3>\n<pre><code class=\"language-javascript\">let person = {\n    name: &quot;\u5f20\u4e09&quot;,\n    age: 25,\n    city: &quot;\u5317\u4eac&quot;\n};\n\n\/\/ for...in \u904d\u5386\u952e\nfor (let key in person) {\n    console.log(`${key}: ${person[key]}`);\n}\n\n\/\/ Object.keys() \u83b7\u53d6\u6240\u6709\u952e\nlet keys = Object.keys(person); \/\/ [&quot;name&quot;, &quot;age&quot;, &quot;city&quot;]\n\n\/\/ Object.values() \u83b7\u53d6\u6240\u6709\u503c\nlet values = Object.values(person); \/\/ [&quot;\u5f20\u4e09&quot;, 25, &quot;\u5317\u4eac&quot;]\n\n\/\/ Object.entries() \u83b7\u53d6\u952e\u503c\u5bf9\u6570\u7ec4\nlet entries = Object.entries(person);\n\/\/ [[&quot;name&quot;, &quot;\u5f20\u4e09&quot;], [&quot;age&quot;, 25], [&quot;city&quot;, &quot;\u5317\u4eac&quot;]]\n<\/code><\/pre>\n<h2>\ud83d\udd04 \u5f15\u7528\u7c7b\u578b<\/h2>\n<h3>\u6570\u7ec4\u548c\u5bf9\u8c61\u662f\u5f15\u7528\u7c7b\u578b<\/h3>\n<pre><code class=\"language-javascript\">\/\/ \u8d4b\u503c\u662f\u5f15\u7528\uff0c\u4e0d\u662f\u590d\u5236\nlet arr1 = [1, 2, 3];\nlet arr2 = arr1;\narr2.push(4);\nconsole.log(arr1); \/\/ [1, 2, 3, 4]\uff08\u4e5f\u88ab\u4fee\u6539\u4e86\uff01\uff09\n\n\/\/ \u5bf9\u8c61\u540c\u7406\nlet obj1 = { name: &quot;\u5f20\u4e09&quot; };\nlet obj2 = obj1;\nobj2.name = &quot;\u674e\u56db&quot;;\nconsole.log(obj1.name); \/\/ &quot;\u674e\u56db&quot;\n<\/code><\/pre>\n<h3>\u590d\u5236\u6570\u7ec4\u548c\u5bf9\u8c61<\/h3>\n<pre><code class=\"language-javascript\">\/\/ \u6570\u7ec4\u590d\u5236\nlet arr = [1, 2, 3];\nlet copy1 = arr.slice();           \/\/ \u65b9\u5f0f1\nlet copy2 = [...arr];               \/\/ \u65b9\u5f0f2\uff08spread\uff09\nlet copy3 = Array.from(arr);        \/\/ \u65b9\u5f0f3\n\n\/\/ \u5bf9\u8c61\u6d45\u590d\u5236\nlet obj = { name: &quot;\u5f20\u4e09&quot;, age: 25 };\nlet copy1 = Object.assign({}, obj); \/\/ \u65b9\u5f0f1\nlet copy2 = { ...obj };              \/\/ \u65b9\u5f0f2\uff08spread\uff09\n\n\/\/ \u6df1\u62f7\u8d1d\uff08\u5d4c\u5957\u5bf9\u8c61\uff09\nlet deepObj = {\n    person: { name: &quot;\u5f20\u4e09&quot;, age: 25 }\n};\nlet deepCopy = JSON.parse(JSON.stringify(deepObj));\n<\/code><\/pre>\n<h2>\ud83c\udfae \u5b9e\u6218\u793a\u4f8b<\/h2>\n<h3>\u793a\u4f8b1\uff1a\u8d2d\u7269\u8f66\u7ba1\u7406<\/h3>\n<pre><code class=\"language-javascript\">class ShoppingCart {\n    constructor() {\n        this.items = [];\n    }\n    \n    addItem(product, price, quantity = 1) {\n        this.items.push({ product, price, quantity });\n    }\n    \n    removeItem(index) {\n        this.items.splice(index, 1);\n    }\n    \n    getTotal() {\n        return this.items.reduce((total, item) =&gt; {\n            return total + item.price * item.quantity;\n        }, 0);\n    }\n    \n    getReceipt() {\n        return this.items.map(item =&gt; \n            `${item.product}: \u00a5${item.price} \u00d7 ${item.quantity}`\n        ).join('\\n');\n    }\n}\n\n\/\/ \u4f7f\u7528\nlet cart = new ShoppingCart();\ncart.addItem(&quot;\u82f9\u679c&quot;, 5.5, 2);\ncart.addItem(&quot;\u9999\u8549&quot;, 3.0, 3);\nconsole.log(cart.getReceipt());\nconsole.log(`\u603b\u8ba1: \u00a5${cart.getTotal()}`);\n<\/code><\/pre>\n<h3>\u793a\u4f8b2\uff1a\u5b66\u751f\u6210\u7ee9\u7ba1\u7406<\/h3>\n<pre><code class=\"language-javascript\">let students = [\n    { id: 1, name: &quot;\u5f20\u4e09&quot;, scores: { math: 90, english: 85 } },\n    { id: 2, name: &quot;\u674e\u56db&quot;, scores: { math: 78, english: 92 } },\n    { id: 3, name: &quot;\u738b\u4e94&quot;, scores: { math: 88, english: 76 } }\n];\n\n\/\/ \u627e\u51fa\u6570\u5b66\u5e73\u5747\u5206\nlet avgMath = students.reduce((sum, student) =&gt; \n    sum + student.scores.math, 0\n) \/ students.length;\n\n\/\/ \u627e\u51fa\u82f1\u8bed\u6700\u9ad8\u5206\u7684\u5b66\u751f\nlet topEnglish = students.reduce((top, student) =&gt; \n    student.scores.english &gt; top.scores.english ? student : top\n);\n\n\/\/ \u7b5b\u9009\u6570\u5b66\u53ca\u683c\u7684\u5b66\u751f\nlet mathPassed = students.filter(s =&gt; s.scores.math &gt;= 80);\n<\/code><\/pre>\n<h3>\u793a\u4f8b3\uff1a\u5f85\u529e\u4e8b\u9879\u5e94\u7528<\/h3>\n<pre><code class=\"language-javascript\">class TodoApp {\n    constructor() {\n        this.todos = [];\n    }\n    \n    add(title) {\n        this.todos.push({\n            id: Date.now(),\n            title: title,\n            completed: false,\n            createdAt: new Date()\n        });\n    }\n    \n    toggle(id) {\n        let todo = this.todos.find(t =&gt; t.id === id);\n        if (todo) {\n            todo.completed = !todo.completed;\n        }\n    }\n    \n    delete(id) {\n        this.todos = this.todos.filter(t =&gt; t.id !== id);\n    }\n    \n    list(filter = 'all') {\n        switch (filter) {\n            case 'active':\n                return this.todos.filter(t =&gt; !t.completed);\n            case 'completed':\n                return this.todos.filter(t =&gt; t.completed);\n            default:\n                return this.todos;\n        }\n    }\n}\n<\/code><\/pre>\n<h2>\u270d\ufe0f \u7ec3\u4e60\u4efb\u52a1<\/h2>\n<h3>\u7ec3\u4e601\uff1a\u6570\u7ec4\u53bb\u91cd<\/h3>\n<pre><code class=\"language-javascript\">function unique(arr) {\n    return [...new Set(arr)];\n}\n\n\/\/ \u6216\u4f7f\u7528 filter\nfunction unique2(arr) {\n    return arr.filter((item, index) =&gt; arr.indexOf(item) === index);\n}\n<\/code><\/pre>\n<h3>\u7ec3\u4e602\uff1a\u6570\u7ec4\u6241\u5e73\u5316<\/h3>\n<pre><code class=\"language-javascript\">function flatten(arr) {\n    return arr.flat();\n}\n\n\/\/ \u6241\u5e73\u5316\u4efb\u610f\u6df1\u5ea6\nfunction flattenDeep(arr) {\n    return arr.flat(Infinity);\n}\n\n\/\/ \u624b\u52a8\u5b9e\u73b0\nfunction flattenManual(arr) {\n    let result = [];\n    arr.forEach(item =&gt; {\n        if (Array.isArray(item)) {\n            result = result.concat(flattenManual(item));\n        } else {\n            result.push(item);\n        }\n    });\n    return result;\n}\n<\/code><\/pre>\n<h3>\u7ec3\u4e603\uff1a\u5bf9\u8c61\u5408\u5e76<\/h3>\n<pre><code class=\"language-javascript\">function mergeObjects(...objs) {\n    return Object.assign({}, ...objs);\n}\n\n\/\/ \u6216\u4f7f\u7528 spread\nfunction mergeObjects2(...objs) {\n    return { ...objs };\n}\n<\/code><\/pre>\n<h2>\ud83c\udf93 \u4eca\u65e5\u6311\u6218<\/h2>\n<p><strong>\u9879\u76ee\uff1a\u56fe\u4e66\u7ba1\u7406\u7cfb\u7edf<\/strong><\/p>\n<pre><code class=\"language-javascript\">class Library {\n    constructor() {\n        this.books = [\n            { id: 1, title: &quot;JavaScript\u9ad8\u7ea7\u7a0b\u5e8f\u8bbe\u8ba1&quot;, author: &quot;Nicholas&quot;, available: true },\n            { id: 2, title: &quot;\u6df1\u5165\u6d45\u51faNode.js&quot;, author: &quot;\u6734\u7075&quot;, available: true },\n            { id: 3, title: &quot;CSS\u63ed\u79d8&quot;, author: &quot;Lea Verou&quot;, available: false }\n        ];\n        this.borrowed = {};  \/\/ { userId: [bookIds] }\n    }\n    \n    \/\/ \u6dfb\u52a0\u56fe\u4e66\n    addBook(title, author) {\n        let id = this.books.length + 1;\n        this.books.push({ id, title, author, available: true });\n        return id;\n    }\n    \n    \/\/ \u501f\u4e66\n    borrowBook(userId, bookId) {\n        let book = this.books.find(b =&gt; b.id === bookId);\n        if (!book || !book.available) {\n            return false;\n        }\n        book.available = false;\n        if (!this.borrowed[userId]) {\n            this.borrowed[userId] = [];\n        }\n        this.borrowed[userId].push(bookId);\n        return true;\n    }\n    \n    \/\/ \u8fd8\u4e66\n    returnBook(userId, bookId) {\n        let book = this.books.find(b =&gt; b.id === bookId);\n        if (!book) return false;\n        \n        book.available = true;\n        this.borrowed[userId] = this.borrowed[userId]\n            .filter(id =&gt; id !== bookId);\n        return true;\n    }\n    \n    \/\/ \u67e5\u627e\u56fe\u4e66\n    searchBooks(keyword) {\n        return this.books.filter(book =&gt; \n            book.title.includes(keyword) || \n            book.author.includes(keyword)\n        );\n    }\n    \n    \/\/ \u5217\u51fa\u53ef\u501f\u56fe\u4e66\n    listAvailable() {\n        return this.books.filter(book =&gt; book.available);\n    }\n}\n<\/code><\/pre>\n<h2>\ud83d\udca1 \u6700\u4f73\u5b9e\u8df5<\/h2>\n<h3>1. \u4f7f\u7528 const \u58f0\u660e\u6570\u7ec4<\/h3>\n<pre><code class=\"language-javascript\">const arr = [1, 2, 3];\narr.push(4);  \/\/ \u2705 \u53ef\u4ee5\u4fee\u6539\u5185\u5bb9\n\/\/ arr = [];  \/\/ \u274c \u4e0d\u80fd\u91cd\u65b0\u8d4b\u503c\n<\/code><\/pre>\n<h3>2. \u4f7f\u7528\u89e3\u6784<\/h3>\n<pre><code class=\"language-javascript\">\/\/ \u6570\u7ec4\u89e3\u6784\nlet [first, second, ...rest] = [1, 2, 3, 4, 5];\n\n\/\/ \u5bf9\u8c61\u89e3\u6784\nlet { name, age } = person;\n<\/code><\/pre>\n<h3>3. \u4f7f\u7528\u53ef\u9009\u94fe<\/h3>\n<pre><code class=\"language-javascript\">let city = person?.address?.city;  \/\/ \u5b89\u5168\u8bbf\u95ee\n<\/code><\/pre>\n<h3>4. \u907f\u514d\u76f4\u63a5\u4fee\u6539\u539f\u6570\u7ec4<\/h3>\n<pre><code class=\"language-javascript\">\/\/ \u274c \u4fee\u6539\u539f\u6570\u7ec4\narr.sort();\n\n\/\/ \u2705 \u521b\u5efa\u65b0\u6570\u7ec4\nlet sorted = [...arr].sort();\n<\/code><\/pre>\n<hr>\n<p><strong>\u5b66\u4e60\u65f6\u95f4<\/strong>: 2026-03-07 16:30<br \/>\n<strong>\u96be\u5ea6<\/strong>: \u2b50\u2b50\u2b50\u2b50\u2606<br \/>\n<strong>\u9884\u8ba1\u7528\u65f6<\/strong>: 3-4 \u5c0f\u65f6<br \/>\n<strong>\u5173\u952e\u8bcd<\/strong>: \u6570\u7ec4, \u5bf9\u8c61, \u65b9\u6cd5, \u5f15\u7528\u7c7b\u578b<br \/>\n<strong>\u76f8\u5173\u6807\u7b7e<\/strong>: #02-\u53d8\u91cf\u4e0e\u6570\u636e<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Day 6: \u6570\u7ec4\u4e0e\u5bf9\u8c61 \ud83c\udfaf \u5b66\u4e60\u76ee\u6807 \u6df1\u5165\u7406\u89e3\u6570\u7ec4\u7684\u64cd\u4f5c\u548c\u5e38\u7528\u65b9\u6cd5 \u638c\u63e1\u5bf9\u8c61\u7684\u521b\u5efa\u3001\u8bbf\u95ee\u548c\u64cd\u4f5c \u5b66\u4f1a\u4f7f\u7528\u6570\u7ec4 &#8230; <a title=\"Day-6-\u6570\u7ec4\u4e0e\u5bf9\u8c61\" class=\"read-more\" href=\"https:\/\/www.resilence.cn\/?p=229\" aria-label=\"\u7ee7\u7eed\u9605\u8bfbDay-6-\u6570\u7ec4\u4e0e\u5bf9\u8c61\">\u9605\u8bfb\u66f4\u591a<\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-229","post","type-post","status-publish","format-standard","hentry","category-studycoding"],"_links":{"self":[{"href":"https:\/\/www.resilence.cn\/index.php?rest_route=\/wp\/v2\/posts\/229","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.resilence.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.resilence.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.resilence.cn\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.resilence.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=229"}],"version-history":[{"count":1,"href":"https:\/\/www.resilence.cn\/index.php?rest_route=\/wp\/v2\/posts\/229\/revisions"}],"predecessor-version":[{"id":230,"href":"https:\/\/www.resilence.cn\/index.php?rest_route=\/wp\/v2\/posts\/229\/revisions\/230"}],"wp:attachment":[{"href":"https:\/\/www.resilence.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.resilence.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.resilence.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}