Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/414.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/json/13.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
将对象创建到对象Javascript中_Javascript_Json_Object - Fatal编程技术网

将对象创建到对象Javascript中

将对象创建到对象Javascript中,javascript,json,object,Javascript,Json,Object,我有下面的代码,我想在for循环中获得相同的结果 有办法做到吗 function makeNode(){ let node = {value: 0, next :{} }; let randon_number = Math.floor(Math.random() * (100 -1)) + 1; node.value = randon_number; node.next = {}; return node; } function nodeList (

我有下面的代码,我想在for循环中获得相同的结果

有办法做到吗

function makeNode(){
    let node = {value: 0, next :{} };
    let randon_number = Math.floor(Math.random() * (100 -1)) + 1;
    node.value = randon_number;
    node.next = {};
    return node;
}   
function nodeList (){
    let node = makeNode();
    node.next = makeNode();
    node.next.next = makeNode();
    node.next.next.next = makeNode();
    node.next.next.next.next = makeNode();
    return node;
}
输出:


{“value”:45,“next”:{“value”:32,“next”:{“value”:52,“next”:{“value”:89,“next”:{“value”:32,“next”:{}}

使用
for
循环

函数makeNode(){
返回{
值:Math.floor(Math.random()*(100-1))+1,
下一个:{}
};
}
函数makeNodeList(长度){
让nodeList=makeNode()
设currentNode=nodeList
for(设i=1;i
。作为控制台包装器{
最大高度:100%!重要;
排名:0;
}