[Vuejs]-What does "const [, xxx]" mean?

1👍

It’s called array destructuring.

In your case const [, name] = key.match(/\/(.+)\.md$/); is the same as const name = key.match(/\/(.+)\.md$/)[1]

0👍

It means take the second value from the array returned by key.match and assign it to the variable name

const [a, b] = [123, 456];
console.log('a:', a, 'b:', b);   // a = 123, b = 456

const [, d] = [111, 222];
console.log('d:', d);            // d = 222
👤gman

Leave a comment