Array of JavaScript notes keyword (store and release & stack & by value Reference)

Source: Internet
Author: User

1. Array creation and initialization

var obj=new Array ();

var arr=[];

Can be extended to a certain length, the literal defines the array

2. Stack by value Pass reference type

An array is a reference type, not a value pass,

Stack: Automatic allocation and release of the barrel, such as function parameters, local variables advanced after the first-level cache

Heap: Usually released by the programmer, the system recycles the FIFO two cache at the end of the program

3. Associative arrays and indexed arrays

Associative array is a hash array, essentially JS bottom, all objects are associative arrays

so the following writing can produce running results, can run the result:2var keys=[1,2,3,4];console.log (keys["1"]);

4.example Delete array repeating unit with hash array

function f (ARR)
{
var arrc=[];
Take out the first element of Arr, put the first one in the ARRC array
ARRC[1]=ARR[0];
Iterates through an array of arr, starting with 1, extracting elements, compared to elements in ARRC
for (Var i=0;i<arr.length;i++)
{
for (Var j=0;j<arrc.length;j++)
{
if (Arrc[j]==arr[i])
break;//equal to the end of this search

Unequal is assigned to the following array,
if (j==length-1)
Arrc[arrc.length]=arr[i];
}
}
return ARRC;
}

Console.log (f ([1,2,2,1,4,5]));

Array of JavaScript notes keyword (store and release & stack & by value Reference)

Related Article

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.