---restore content starts---
. Pop () removes the element at the end of the array var removedfrommyarray=myarray.pop () Removes the last element of the MyArray array and assigns it to Removedfrommyarray
. Shift removes the first element of the array from Var removedfrommyarray=myarray.shift () and assigns the first elements of the MyArray array to a removedfrommyarray
. push () Adds an element at the end of the array. Unshift () Add an element example at the beginning of the array: Myarray.push (["Paul", 35]);
A program may have local variables and global variables with the same name. In this case, the 局部
variable will take precedence over the 全局
variable.
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));
Write a function queue
that uses an array arr
and a number item
as arguments. The number is item
added to the end of the array, then the first element of the group is moved, and the last queue function should return the deleted element.
Return is a good thing return a<b; automatically compares the size of a and B, and then returns a Boolean value
Math.random () randomly extracts a decimal number from 0 to 1, including 0 but excluding 1
---restore content ends---
FREECODECAMP-JS Basic Section