HI, i have this code
let key = N001DSC29MC22HC22DD04MD09YD21
function get(key) {
let res = {};
res.matchNumber = key.match(/(?<=N)\d{3}/g);
res.matchSeconds = key.match(/(?<=DSC)\d{2}/g);
res.matchMinutes = key.match(/(?<=MC)\d{2}/g);
res.matchHours = key.match(/(?<=HC)\d{2}/g);
res.matchDay = key.match(/(?<=DD)\d{2}/g);
res.matchMonth = key.match(/(?<=MD)\d{2}/g);
res.matchYear = key.match(/(?<=YD)\d{2}/g);
res.title = JSON.parse(localStorage.getItem(key)).title;
res.description = JSON.parse(localStorage.getItem(key)).description;
Object.keys(res).forEach(key => {
if (! res[key]) delete res[key]
if (Array.isArray(res[key])) res[key] = res[key].join('')
})
return res;
}
get(key)
As you can see my code not clean, there is any better way to do the same function. I really try and i can't do better
I Mean there is better from using REGEXP And match very mush Like this