Is there a way in Javascript to generate an object , for example
function newObject(name,value) {
// Some Awesome Logic
return theObject
}
var test = newObject('mike',32);
And The return from new object to be an object
console.log(test); // returns an object
{
"mike": 32
}
I need a function like this to be reusable... HELP PLEASE
const newObject = (k, v) => ({[k]: v});But it's not obvious how this is better than simply using the object literal in-place.