> 旅游
es6解构方法(es6解构符号)
导语:ES6解构-实例
1、复杂多级的对象解构
let obj = { match: { params: { id: , tab: } } }// 获取id和tabconst { match: {params: {tab,id}}} = obj;console.log(tab); //‘index’console.log(id); //‘1’// 获取paramsconst { match: {params}} = obj;console.log(params); //{id: , tab: }// 获取matchconst { match} = obj;console.log(match) ; // {params: {…}}
2、对象数组解构
let obj = { isTrue: false, list: [&39;, &39;] } const {list: [list1, list2]} = obj // list1 &39; // list1 &39; let arr = [1,2,3,4,5];const [arr1,arr2,...reset] = arr;// arr1 -> 1// arr2 -> 2// reset => [3,4,5]let arr = [1,2,3,4,5];var [,,,value] = arr;// value => 4
ES6解构实例
本文内容由小姿整理编辑!