Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140705

create object from array, using recursion/reduce?

$
0
0

I'm just kind of lousy with recursive functions.

I want to turn this...

const input = { regions: ["US", "CA", "LA"], checked: true };

...into the following, using recursion and reduce:

const output = {
  US: {
    CA: {
      LA: true
    }
  }
};

Help? I've tried lots of things, but my experiments are too embarrassing to share.


Viewing all articles
Browse latest Browse all 140705

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>