解构数组获得第二个值? [英] Destructuring array get second value?
本文介绍了解构数组获得第二个值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用销毁获取数组?
How to get array using destructing?
const num = [1,2,3,4,5];
const [ first ] = num; //1
console.log(first)
我可以得到1,但是当我尝试执行const [ null, second ] = num
时,它具有预期的令牌错误.如何获得num数组的第二项?
console.log(first)
I'm able to get 1, but when I try to do const [ null, second ] = num
it has expected token error. How to get 2nd item of num array?
推荐答案
您只需输入逗号即可跳过参数名称
You can skip parametr name just by putting comma
var num = [1, 2, 3, 4, 5];
var [ ,x] = num;
这篇关于解构数组获得第二个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文