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

How to store text and pictures in MySQL

Large Text Data Types in Oracle Clob long text ty...

How to create a MySQL database and support Chinese characters

Let's first look at the MySQL official docume...

MySQL 5.7.20 free installation version configuration method graphic tutorial

I have seen many relevant tutorials on the Intern...

How to capture exceptions gracefully in React

Table of contents Preface ErrorBoundary Beyond Er...

Detailed explanation of Socket (TCP) bind from Linux source code

Table of contents 1. A simplest server-side examp...

Experience in solving tomcat memory overflow problem

Some time ago, I submitted a product version to t...

Several methods to execute sql files under mysql command line

Table of contents The first method: When the MySQ...

Detailed explanation of MySQL multi-table join query

Table of contents Multi-table join query Inner Jo...

How to implement vertical text alignment with CSS (Summary)

The default arrangement of text in HTML is horizo...

Solution to Docker pull timeout

Recently, Docker image pull is very unstable. It ...

How to create Baidu dead link file

There are two types of dead link formats defined b...

How to enable MySQL remote connection

For security reasons, MySql-Server only allows th...

Share the pitfalls of MySQL's current_timestamp and their solutions

Table of contents MySQL's current_timestamp p...

Introduction to building a DNS server under centos7

Table of contents 1. Project environment: 2: DNS ...