How to use foreach to traverse arrays in Vue
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.