In es6, how can i simplify the following lines using destructuring?:
const array0 = someArray[0].data; const array1 = someArray[1].data; const array2 = someArray[2].data;
Whether using destructuring would actually be a simplification is debatable but this is how it can be done:
const [ { data: array0 }, { data: array1 }, { data: array2 } ] = someArray
Live Example:
const someArray = [ { data: 1 }, { data: 2 }, { data: 3 } ]; const [ { data: array0 }, { data: array1 }, { data: array2 } ] = someArray console.log(array0, array1, array2);
1.4m articles
1.4m replys
5 comments
57.0k users