I found compact
function very useful (in php). Here is what it does:
$some_var = \'value\';
$ar = compact(\'some_var\');
//now $ar is array(\'so
No there is no analogous function nor is there any way to get variable names/values for the current context -- only if they are "global" variables on window
, which is not recommended. If they are, you could do this:
function compact() {
var obj = {};
Array.prototype.forEach.call(arguments, function (elem) {
obj[elem] = window[elem];
});
return obj;
}