Is there a function in javascript similar to compact from php?

后端 未结 4 618
醉梦人生
醉梦人生 2021-01-18 15:24

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         


        
4条回答
  •  走了就别回头了
    2021-01-18 16:05

    You can also use phpjs library for using the same function in javascript same as in php

    Example

    var1 = 'Kevin'; var2 = 'van'; var3 = 'Zonneveld';
    compact('var1', 'var2', 'var3');
    

    Output

    {'var1': 'Kevin', 'var2': 'van', 'var3': 'Zonneveld'}
    

提交回复
热议问题