Skip to content

Latest commit

 

History

History
39 lines (29 loc) · 1006 Bytes

ignore-items-from-array-destructuring.mdx

File metadata and controls

39 lines (29 loc) · 1006 Bytes
category created tags title
Tip
2021-02-28
JavaScript
Ignore items from array destructuring

When destructuring an array, you can skip certain items by using blanks:

const dateTime = '2021-02-28T14:57:00';

// Ignore the date part
const [, time] = dateTime.split('T');

// Ignore the seconds
const [hours, minutes] = time.split(':');

hours; // '14'
minutes; // '57'

If you are working in a team, then it's a good idea to add comments for skipped items. It also makes the code more readable:

const [
    ,
    // date
    time,
] = dateTime.split('T');

const [hours, minutes /* seconds */] = time.split(':');

See also