Javascript-hash array for in function

Source: Internet
Author: User

1 what is an array: In memory, storage space for multiple data storage, and then a name why;2 Why: The reality of storing multiple related data, are centralized storage, a common name3 4program = data structure +algorithm5 good data structure can greatly improve the execution efficiency of the program.6 when to use arrays, as long as the contiguous storage of multiple related data is used in the array7 How to use arrays:8 9 Create arrays: 3 typesTen I. Creating an empty array One1. Create an empty array:varArr=[]; A2. Using NEW:varArr=NewArray (); -  - two. Create an array at the same time, initialize the array's data: the1. Array Direct Volume:vararr=[value 1,2,3,4,5,6,....] -2. Using NEW:varArr=NewArray (Value 1,2,3,4,5,6,. ..) -  - Three. Create a n-room +  - the length property of the array: + identifies the number of theoretically elements in an array AIn any case: length is always the maximum subscript +1 at Fixed Routines -Shrink: arr.length-- -1. Last element: Arr[arr.length-1] -2. The nth element of the countdown: arr[arr.length-N] -3. Append new elements: arr[arr.length]=new value; - Special case: The array in JS: 3 Unlimited in1. Types of elements that are not restricted -2. Do not limit subscript out of bounds to get element value: + Subscript out of bounds: no error, return undefined -3. Unlimited number of elements the To set the element value: *1. Last element: Arr[arr.length-1] $2. The nth element of the countdown: arr[arr.length-N]Panax Notoginseng3. Append new elements: arr[arr.length]=new value; - Subscript out of bounds: the automatically in the specified value +  AIf not found, return-1 the  +  - An array is an object of a reference type $  $ Garbage Collection - periodically reclaims objects that are no longer referenced by any variables. Frees memory.  -1. Garbage collector: the accompanying the main program, and running a small program - periodically reclaims objects in memory that are not referenced by any variableWuyi2. Reference counters: the on each object, a property that marks the number of variables that are referencing the object -Each more than one variable refers to the object, the counter is +1 WuIf a variable releases a reference to an object by assigning a value of NULL, the counter-1 -Until the counter is 0, indicating that no more variables refer to the object, the object is recycled/disposed About Recommendation: If you are using a large object, you should actively assign null.  $  - Access element: -lxr["Name"] - emphasizing length invalidation of associative arrays A traversal cannot be broken with for + loop with for in theWhere in, which means that each subscript in the array is removed in order for (varKeyinchhash) { -     //Key Gets the subscript name of each element $ Hash[key] Current element value the } the  theAssociative array/hash array principle: the hash algorithm: Receives a string and calculates a sequence number that is as distinct as possible - The same string, the calculated number is always the same in different strings, the most calculated numbers are not duplicated the  the Deposit Data: About The hash algorithm receives a string that is labeled below and calculates an ordinal number that is not duplicated. Storing data in an array position corresponding to an ordinal the Get Data: the The subscript name into a hash algorithm, calculated and deposited exactly the same sequence number, directly to the ordinal position to find the element the advantages, find extremely fast +and the number of elements in the array, and the position of the elements in the arrays regardless

<! DOCTYPE html>//var lxr=[];//lxr["name"]= "Forest Heart as";//lxr["math"]=83;//lxr["CHS"]=93;//lxr["Eng"]=80;//Console.log (LXR);//Console.log (lxr["math"]);////Traversal//For (var key in LXR) {//Console.log (key+ ":" +lxr[key]);//    }///*****************************************/    varArr=[' A ', ' B ', ' C ', ' B ', ' a ']; functionuniqual (arr) {//iterate through each element in arr while declaring an empty array Uarr     for(varI= 0,uarr=[]; i<arr.length;i++){        //iterate through each element in the Uarr         for(varj=0;j<uarr.length;j++){            //if the current element in Uarr equals the current element in Arr            if(uarr[j]==Arr[i]) {                 Break;//exit loop//Traverse end            }        }        //if J equals the length of Uarr        if(j==uarr.length) {Uarr[j]=arr[i];//joins the current element in Arr into the Uarr}//Traversal End    }        //back to Uarr    returnUarr; }    varUarr=uniqual (arr); Console.log (String (Uarr)); //ABC</script></body>

Javascript-hash array for in function

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.