JavaScript judgment, Loop, Map, Set

Source: Internet
Author: User
Tags delete key iterable

This article is the author's personal summary of some of the judging conditions when looking at the Liaoche teacher JavaScript tutorial nullundefined0NaNand an empty string ‘‘As false, all other values are considered true, so the result of the above code condition judgment is trueLoop 1.for (same c) 2.while (same as C) 3.do while (same as C) Variant for...in Traversal object only Traverse property, no value for property Iterating through an array only iterates through the index, the result is that the string is not numble not 1 is a ' 1 ' so array is also an object, and the index value is its attribute map MapIs the structure of a set of key-value pairs with extremely fast lookup speeds. Initialization MapRequires a two-dimensional array, or directly initializes an empty Map            Map method  1.get (key)   Get value               & nbsp      2.set (key: Value)   Add an element                      3.h As (key)   Find if this key is included   return true  false                   &NBSP ; 4.delete (key)   Delete this key             A key can only correspond to one value, so the value is placed on a key more than once, and subsequent values will flush out the previous value.             set              Set is a set of keys, but does not contain Value And key cannot be duplicated                 Repeat elements are automatically filtered out                 Add key                via delete () to delete key     via Add ()           iterable                This is a type     &NBS P       &NBSP   iterating through an array first can take the subscript loop, but traversing the map and set cannot use subscripts. So in order to unify iterable occasional, array,map,set are iterable type                 Collections that belong to the Iterable type can use For....of ... Loop to traverse                 Iterate array set   value pair value           &NBSP ;     Traverse map  x[0]: Key  x[1]: value                   &NB sp;                 for...in   and   for...of difference     &NB Sp                for...in traversal is the object's property name             & nbsp                          for...of The value of the object is traversed    &N bsp;                                       for...of only iterates through the collection itself, post-join properties do not traverse         &NBSp                  :  iterable built-In a foreach method that receives a function that automatically callbacks the function every time it is iterated                          ,         &NB Sp     Example: var a = [' a ',  ' B ',  ' C '];a.foreach (function ,  array)  {   // element:  point to the value of the current element    // index:  points to the current index    // array:  points to the array object itself     alert (element); });function (element, index, array) This is an anonymous function three parameter names are defined by themselves but the order of the foreach incoming parameters is deterministic, and the separate representation is also deterministic. Executes the function once per iteration down MapThe callback function parameters are in sequence valuekeyAnd mapThe callback function parameters of the set itself are element, Samee lementand set itself

JavaScript judgment, Loop, Map, Set

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.