JSFiddle - React, Tailwind, and code Playground
JavaScript
function myFunction (a, blabla, c, somethingElse, e, f) {
var obj = [];
//'(a, b, c, d, e, f)'
var tmp = arguments.callee.toString().match(/\(.*?\)/g)[0];
//["a", "b", "c", "d", "e", "f"]
var argumentNames = tmp.replace(/[()\s]/g,'').split(',');
[].splice.call(arguments,0).forEach(function(arg,i) {
obj.push({
// question is how to get variable name here?
name: argumentNames[i],// "a", "b", "c", "d", "e", "f"
value: arg, //a, b, c, ,d, e, f
})
});
return obj;
}
console.log(JSON.stringify(myFunction(1, 2, 3, 4, 5, 6)));