Methods and Techniques for retrieving Value from a JS recursive traversal object, recursive value

Source: Internet
Author: User

Methods and Techniques for retrieving Value from a JS recursive traversal object, recursive value

To use recursion, You need to determine whether the object is the same as the parent type. This article demonstrates 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 );

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

The above section describes all the methods and techniques used to obtain the Value of a JS recursive traversal object. I hope this will be helpful to you. If you have any questions, please leave a message for me, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.