js 字符串转数组,数组解构默认值 All In One

js 字符串转数组,数组解构默认值 All In One

bug ❌

const [year,month,day,title] = [1,2];
year;
// 1
day;
// undefined

image

solution ✅

const [year = 'a1',month = 'a2',day = 'a3',title = 'a4'] = [1,2];

year;
// 1
day;
// 'a3'

image

image

refs



©xgqfrms 2012-2020

www.cnblogs.com/anonymous007 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️anonymous007, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2022-11-30 03:27  anonymous007  阅读(32)  评论(2编辑  收藏  举报