Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use foreach to traverse arrays in Vue

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to use foreach traversal array in Vue" related knowledge, editor through the actual case to show you the operation process, the method of operation is simple and fast, practical, I hope that this "how to use foreach traversal array in Vue" article can help you solve the problem.

Traversing the array in js

/ / define the shift detail array var bcglxiangxiList = new Array (); / / define the shift detail object var bcxiangxi = {}; / / the parameter bcglXiangXiListParam.forEach passed in the loop (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]; / / Save the shift detail object into the shift detail array bcglxiangxiList.push (bcxiangxi);})

Traversing the 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, and it can also be traversed with two parameters in js.

/ / define shift detail array var bcglxiangxiList = new Array (); / / define shift detail object var bcxiangxi = {}; / / parameters passed in the loop 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]; / / Save the shift detail object into the shift detail array bcglxiangxiList.push (bcxiangxi);}) Vue forEach cycle uses / / data for the collection data.forEach (function (item, index) {/ / item is the index of the loop to which the object / / index is the loop, starting from 0}) this is the end of the introduction on "how to use foreach in Vue to traverse the array". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report