JS Recursive Traversal Object to Obtain Value Value Method Skills

  • 2021-06-28 10:38:11
  • OfStack

1 Recursion is usually used to determine whether the object is the same as the parent type. This article shows you simple object recursion and array recursion.


var obj = { a:{w:1,y:2,x:3},
b:{s:4,j:5,x:6},
c:{car:7,cat:8,mao:9}
}
function f(s){
for(var i in s){
if(typeof s[i]=="object"){
f(s[i])
}else{
 * console.log(s[i]);
 * }
}
}
f(obj);

Return results: 1,2,3,4,5,6,7,8,9


Related articles: