Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何更好地保存数组中所有对象的子对象?_Javascript_Arrays_Loops_Vue.js_Object - Fatal编程技术网

Javascript 如何更好地保存数组中所有对象的子对象?

Javascript 如何更好地保存数组中所有对象的子对象?,javascript,arrays,loops,vue.js,object,Javascript,Arrays,Loops,Vue.js,Object,所以我在Vue中创建了一个项目,我想迭代所有的['monitors',并保存不同的部分。我怎样才能做到最好? 谢谢 listOfAllTrips=this.wlData['monitors'][0]。行[0]。出发; listOfAllTrips2=this.wlData['monitors'][1]。行[0]。偏差; listOfAllTrips3=this.wlData['monitors'][2]。行[0]。偏差; 这里是一个使用Ecma脚本数组映射函数的迭代,该函数将处理所有tri

所以我在Vue中创建了一个项目,我想迭代所有的['monitors',并保存不同的部分。我怎样才能做到最好? 谢谢


listOfAllTrips=this.wlData['monitors'][0]。行[0]。出发;
listOfAllTrips2=this.wlData['monitors'][1]。行[0]。偏差;
listOfAllTrips3=this.wlData['monitors'][2]。行[0]。偏差;
这里是一个使用Ecma脚本数组映射函数的迭代,该函数将处理所有trip的列表超过正式硬编码的3个时的情况

现在要访问每个出发点,您只需提供访问索引,例如

listOfAllTrips[1]

这将返回第二次行程,因为数组索引从0开始。您可以使用函数
map
和分解分配,如下所示:

设m=[{lines:[{departments:[“Ele”,“Stack”]}],{lines:[{departments:[“Ele2”,“Stack2”]}]}];
让result=m.map({lines:[偏离]})=>偏离);

控制台日志(结果)
listOfAllTrips=this.wlData['monitors'].map(monitor=>monitor.lines[0]。出发)非常感谢ritaj,这正是我想要的!:-)
listOfAllTrips[1]