JS foreach function considerations (break, continue)

Source: Internet
Author: User

Description of the Foreach API:

Https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach

Description

forEach The scope of the traversal is callback determined before the first call . forEach items added to the array after the call are not callback accessed . If the values that already exist are changed, the values passed to callback them are the forEach values that are traversed to their moment. Deleted items are not traversed to. If the accessed element is deleted at iteration (for example shift() , used), then the element will be skipped

Example:

<!DOCTYPE HTML><HTMLLang= "zh">    <Head>        <MetaCharSet= "UTF-8" />        <Metaname= "Viewport"content= "Width=device-width, initial-scale=1.0" />        <Metahttp-equiv= "X-ua-compatible"content= "Ie=edge" />        <title>JS foreach function considerations</title>    </Head>    <Body>        <Scriptsrc= "Https://cdn.bootcss.com/lodash.js/4.17.10/lodash.min.js"></Script>        <Scripttype= "Text/javascript">            varwords= [" One", " Both", "three", " Four"]; Words.foreach (function(Word) {console.log (word); if(Word=== " Both") {                    //will change the output order                    //Words.shift ();                    //does not change the output orderWords.push ('5')                    //cannot use break                    // Break                    //cannot use continue                    //Continue                }            }); </Script>    </Body></HTML>

JS foreach function considerations (break, continue)

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.