将对象创建到对象Javascript中
我有下面的代码,我想在for循环中获得相同的结果 有办法做到吗将对象创建到对象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 (
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;
}