I have an object that I receive from html form, and it has the following syntax:
'ingredients[0][name]': 'eggplant',
'ingredients[0][mass]': '1',
'ingredients[0][units]': 'pc',
'ingredients[1][name]': 'cheese',
'ingredients[1][mass]': '150',
'ingredients[1][units]': 'gr',
'ingredients[2][name]': 'cilantro',
'ingredients[2][mass]': '100',
'ingredients[2][units]': 'tt' ...
All that I need is to convert these key-value pairs into the one big object field. Such as
recipe = {
ingredients: [
{
name: 'epplant',
mass: '1',
units: 'pc'
},
{
name: 'cheese',
mass: '150',
units: 'gr'
}, ...
]
}
How can I do this without JQuery or other JS-framework?