標籤:
---恢複內容開始---
.pop() 將數組末尾的元素移除 var removedFromMyArray=myArray.pop() 將myArray數組的最後一個元素移除並賦給removedFromMyArray
.shift 將數組第一個元素移除 var removedFromMyArray=myArray.shift() 將myArray數組的第一個元素移除並賦給removedFromMyArray
.push() 在數組末尾添加元素 .unshift() 在數組開頭添加元素 例:myArray.push(["paul",35]);
一個程式中有可能具有相同名稱的 局部 變數 和 全域 變數。在這種情況下,局部 變數將會優先於 全域 變數。
function queue(arr, item) { // Your code here arr.push(item); return arr.shift(); // Change this line}// Test Setupvar testArr = [1,2,3,4,5];// Display Codeconsole.log("Before: " + JSON.stringify(testArr));console.log(queue(testArr, 6)); // Modify this line to testconsole.log("After: " + JSON.stringify(testArr));
寫一個函數 queue ,用一個數組arr和一個數字item作為參數。數字item添加到數組的結尾,然後移出數組的第一個元素,最後隊列函數應該返回被刪除的元素。
return是一個好東西 return a<b;自動比較a和b的大小,然後返回布爾值
Math.random()從0到1中隨機抽取一個小數 包括0但是不包括1
---恢複內容結束---
FreeCodeCamp-JS基礎部分