Here's the scenario: I have a file name in this format:
const fn = 'xy_20181023_ABCD.jpg';
My goal is to break this down into variables x, y, date, data
as follows:
console.log({x, y, date, data});
// {
// data: "ABCD.jpg"
// date: "20181023"
// x: "x"
// y: "y"
// }
I'm aware that I can achieve this with the following code:
const [temp, date, data] = fn.split('_');
const [x, y] = temp[0]
However, my question is: Can this assignment be done in a single line? Extra points if it remains easy to understand.
Cheers,
P