Here is a code snippet I have:
const burger = `<div class="card" data-id="42" data-price="15" data-category="popular">`
I am trying to create the following object:
const obj = { id: 42, price: 15, category: 'popular' }
To achieve this, I am using the following function:
let regex = /(?<name>\w+)="(?<value>\w+)"/g;
let results = burger.matchAll(regex);
for(let result of results) {
let {name, value} = result.groups;
let values = `${name}: ${value}`;
console.log(values)
}
The output I am currently getting is not what I desire:
> "class: card"
> "id: 42"
> "price: 15"
> "category: popular"