I have the following code:
const burger = `<div class="card" data-id="42" data-price="15" data-category="popular">`
i need the following object:
const obj = { id: 42, price: 15, category: 'popular' }
With this function:
let regex = /(?<name>\w+)="(?<value>\w+)"/g;
let results = burger.matchAll(regex);
for(let result of results) {
let {name, value} = result.groups;
let valores = `${name}: ${value}`;
console.log(valores)
}
I get the following, but it is not what I want
> "class: card"
> "id: 42"
> "price: 15"
> "category: popular"