Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从json对象动态创建变量_Json_Node.js_Variables - Fatal编程技术网

从json对象动态创建变量

从json对象动态创建变量,json,node.js,variables,Json,Node.js,Variables,需要动态查找数组的长度,并对json对象的键值进行变量化 所需产出: var a={LogGroupName:'/sam/xxx/ab/xxx/ayb/lob-star',LogStreamName:'tsy98',S3_Bucket:'abc'}; var array=[a]; console.log(array); [ { LogGroupName: '/sam/xxx/ab/xxx/ayb/lob-star',LogStreamName: 'tsy98',S3_Bucket: 'abc'

需要动态查找数组的长度,并对json对象的键值进行变量化

所需产出:

var a={LogGroupName:'/sam/xxx/ab/xxx/ayb/lob-star',LogStreamName:'tsy98',S3_Bucket:'abc'};
var array=[a];
console.log(array);
[ { LogGroupName: '/sam/xxx/ab/xxx/ayb/lob-star',LogStreamName: 'tsy98',S3_Bucket: 'abc' } ]

需要帮助。

您发布的代码中没有任何数组。虽然您可以使用
eval
进行此操作,但这确实是一个X/Y问题,您实际上在尝试实现什么?请查找更新的问题以明确说明。我想初始化json对象中的所有变量;
LogGroupName=/sam/xxx/ab/xxx/ayb/lob-star
console.log(LogGroupName);