Generally speaking, recursion is used to determine whether the object is the same as the parent type. Through this article, we will demonstrate simple object recursion, and array recursion is similar.
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
The above is the complete description of the method and techniques for obtaining value by JS recursive traversal objects introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!