Array functions inside arrays

Source: Internet
Author: User

Concat () function: Merges an array and generates a new array. There is no change to the original array. When a parameter is not passed, it is equivalent to generating a new array. Format: Array. concat (Data ... Array); return value: A sample of the new array code generated:
1 //. Concat (' array element to add ')2 vararr = [11, 13, 22, 33];3 varARR1 = Arr.concat (44, 55);//add two elements to arr array,4 //and generates a new array without changing the original array of arr. 5Alert (arr);//One , one, one, one.6Alert (Arr.concat (88, 88));//11,13,22,33,88,887alert (ARR1);//11,13,22,33,44,558 varARR1 = [10, 20, 30];9 varARR2 = [40, 50, 60];Ten vararr = Arr1.concat (arr2, 10,true, [30, 40]); One alert (arr.length); Aalert (ARR1);//Ten, A, a, a, a, ten, A, true, -alert (ARR2);//Max , Max. -  

 

-----in-array functions     stacks  --------------------------------------------------------------                  Stacks: Ancient wooden pots called stacks.                  Features: Advanced after-out.                  implementation method: From the same head in, Out from the same head.                                   push ()                   format: arrays. Push (parameters)                   parameters: Elements added into the array.                  function: Adds an element to the end of the original array. Modifies the original array directly.                  return Value: The length of the array after the element is inserted.                    pop                 Function: Takes an element from the end of an array and can fetch only one at a time. Modifies the original array directly.                  format: Array. Pop ();                  return value: the removed element    code Example: 
1 //the. push (array Element) adds an array element to the array at the end. Modifies the original array directly. The return value is the length of the array after the element is inserted2 vararr = [' on ', ' Down '];//An array can be a string, a number, a Boolean value. 3 varres = Arr.push (' left ');//The return value of the. push () function is the length of the inserted data. 4Alert (arr);//results on, down, left5Alert (res);//View the length of the array after insertion. 6  7 vararr = [100, 200];//An array can be a string, a number, a Boolean value. 8Arr.push (300);9Alert (arr);//result 100,200,300Ten //pop () takes an array element from the end of the array and creates a new array. Modifies the original array directly. The return value is the number taken away.  One vararr = [100, 200, 300] A varres =Arr.pop () -Alert (arr);//A. -Alert (RES)//The return value of the 300 function is the number taken away. 

Example 2:
1 vararr = ["Iron Man", "Thor", "Captain America"];2 varres = Arr.push ("Ant Man", "Spider-Man.");3Alert (arr);//Iron Man, Thor, Captain America, Ant Man, spider -Man4Alert (res);//55------------------------------------------------------6 vararr = ["Iron Man", "Thor", "Captain America"];7 varres =Arr.pop ();8Alert (arr);//Thunder God, Captain America.9Alert (res);//Iron Man

  -----------------------Stack end------------------------------------------  ----------------- -------in-array functions     queues-----------------------               Queues                   Features: Advanced first out.                  principle of implementation: from the end into, out of the Pai Tau.                  .push                 Shift ()                  Function: Takes an element from the array's Pai tau.                  format: Array. Shift ()                 The return value is the data taken away.                    unshift ()                  function: Inserts an element from the head of an array.                  format: Array. unshift ( Any parameters)                  Return value: The length of the array after the element is inserted    code example: 
//The . Push () usage is the same as above.  //. Shift () goes from the array of the PAI to the element. The return value is the number taken away. Modify the original function directly. vararr = [100, 200, 300];varres =Arr.shift (); alert (res);// -Alert (arr);//,/*-----------------------------------------------------------*/ //. Unshift () inserts an array element from the head of the element. The return value is the length of the inserted array. vararr = [true,false,true];varres = Arr.unshift (false); alert (res);//4Alert (arr);//false,true,false,trueExample 2;vararr = ["Professor X", "Qin", "Laser Eye"];/*Arr.push ("shock wave"); alert (arr);*/ /*var res = arr.shift (); alert (arr);//piano, Laser eye alert (res) ;*///Professor X  /*when you look at. Shift please comment out the. Push and. Unshift to see arr is public*/  varres = Arr.unshift ("Apocalypse", "Thor"); alert (arr);//Apocalypse, Thor, Professor X, Jean, Laser eyeAlert (res);//5
---------------------------------Queue End-------------------------------

Array functions inside arrays

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.