【发布时间】:2019-05-25 11:28:39
【问题描述】:
几乎所有内容都在标题中,但我会给你一个例子:
// i can't know the content of this string but for the exemple she's here
let str = 'elem-0, elem-1, elem-2, elem-3';
// how to properly write this line because this line is not write in an array 'destructuring way'
let array = str.split(',')[0];
// return me : "elem-0" (and he has to)
console.log(array);
【问题讨论】:
-
let [array] = str.split(','); -
取决于你想要达到的目标
标签: javascript arrays destructuring