o9s
is a microblog
home archives search feed blogroll


Get Some Rest

You can use the spread operator to get the rest of the data in an array.

const fruits = [
    'Apple',
    'Orange',
    'Banana',
];
const [first, ...rest] = fruits;

first holds 'Apple' and rest holds ['Orange', 'Banana'].

Did you notice I used trailing commas? Trailing commas are cool.

Posted on 2018-03-24   #javascript     #til  






← Next post    ยท    Previous post →