Description of the writing method of foreach array in Vue and traversal array in js

Description of the writing method of foreach array in Vue and traversal array in js

How to write Vue foreach array and traverse array in js

Scenario

Use Axios in Vue to send get or post requests. When sending requests, you need to use js

Traverse and process the request parameters.

When receiving a response, you need to traverse and process the response result.

Note the difference between foreach arrays in Vue and JS.

accomplish

Iterating over an array in js

//Define the shift details array var bcglxiangxiList = new Array();
  //Define shift details object var bcxiangxi = {};
  // Loop through the parameters bcglXiangXiListParam.forEach(element => {
    bcxiangxi.xh = element.xh;
    bcxiangxi.bcbh = data.bcbh;
    bcxiangxi.dkkssj = element.sjfw[0];
    bcxiangxi.dkjssj = element.sjfw[1];
    bcxiangxi.ts = element.ts;
    bcxiangxi.dkdd = element.dkdd;
    bcxiangxi.zxjxljsj = element.jxsjfw[0];
    bcxiangxi.zdjxljsj = element.jxsjfw[1];
    //Store the shift details object into the shift details array bcglxiangxiList.push(bcxiangxi);
  });

Iterating over an array in vue

 var bcglxiangxiList = new Array();
        var bcxiangxi = {};
        debugger;
        if (
          response.data.bcglXiangXiList != null &&
          response.data.bcglXiangXiList.length > 0
        ) {
          console.log(response.data.bcglXiangXiList);
          response.data.bcglXiangXiList.forEach((item, index) => {
            console.log(item);
            bcxiangxi.xh = item.xh;
            bcxiangxi.bcbh = item.bcbh;
            //debugger
            bcxiangxi.sjfw = new Array();
            bcxiangxi.sjfw[0] = item.dkkssj;
            bcxiangxi.sjfw[1] = item.dkjssj;
            bcxiangxi.ts = item.ts;
            bcxiangxi.dkdd = item.dkdd;
            bcxiangxi.jxsjfw = new Array();
            bcxiangxi.jxsjfw[0] = item.zxjxljsj;
            bcxiangxi.jxsjfw[1] = item.zdjxljsj;
            bcglxiangxiList.push(bcxiangxi);
          });
        }

You can see that the traversal method is the same. In js, you can also use the traversal method with two parameters.

  //Define the shift details array var bcglxiangxiList = new Array();
  //Define shift details object var bcxiangxi = {};
  // Loop through parameters bcglXiangXiListParam.forEach((element,index) => {
    bcxiangxi.xh = element.xh;
    bcxiangxi.bcbh = data.bcbh;
    bcxiangxi.dkkssj = element.sjfw[0];
    bcxiangxi.dkjssj = element.sjfw[1];
    bcxiangxi.ts = element.ts;
    bcxiangxi.dkdd = element.dkdd;
    bcxiangxi.zxjxljsj = element.jxsjfw[0];
    bcxiangxi.zdjxljsj = element.jxsjfw[1];
    //Store the shift details object into the shift details array bcglxiangxiList.push(bcxiangxi);
  });

vue forEach loop usage

//data is a collection data.forEach(function(item, index) {
            //item is the object that is looped on that day //index is the loop index, starting from 0})

The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Vue forEach loop array to get the data you want
  • Detailed explanation of the principle analysis and practical application of Vue array traversal methods forEach and map
  • Vue must learn knowledge points: the use of forEach()

<<:  CentOS 8 Installation Guide for Zabbix 4.4

>>:  Detailed explanation of grep and egrep commands in Linux

Recommend

In-depth understanding of the use of Vue

Table of contents Understand the core concept of ...

Detailed explanation of CSS text decoration text-decoration &amp; text-emphasis

In CSS, text is one of the most common things we ...

Record the whole process of MySQL master-slave configuration based on Linux

mysql master-slave configuration 1. Preparation H...

MySQL Query Cache and Buffer Pool

1. Caches - Query Cache The following figure is p...

Sample code for implementing 3D book effect with CSS

Without further ado, let's take a look at the...

SSH port forwarding to achieve intranet penetration

The machines in our LAN can access the external n...

Solution to JS out-of-precision number problem

The most understandable explanation of the accura...

Two ways to completely delete users under Linux

Linux Operation Experimental environment: Centos7...

HTML implements read-only text box and cannot modify the content

Without further ado, I will post the code for you...

How to deploy services in Windows Server 2016 (Graphic Tutorial)

introduction Sometimes, if there are a large numb...

Detailed explanation of Bootstrap grid vertical and horizontal alignment

Table of contents 1. Bootstrap Grid Layout 2. Ver...

What does this.parentNode.parentNode (parent node of parent node) mean?

The parent node of the parent node, for example, t...

Detailed explanation of Vue's methods and properties

Vue methods and properties 1. Methods Usage 1 met...