SHARE
TWEET

Untitled

a guest Jun 15th, 2019 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Array = [
  2.     { id: 1, child:[] }
  3. ]
  4.  
  5. handleArrayDepth = (Array) => {
  6.  
  7.     Array.map(arrayitem => {
  8.       let id = array.id;
  9.       id++;
  10.       arrayitem.child.push({
  11.         id: id,
  12.         child: []
  13.       });
  14.       if (id < 2) {
  15.         this.handleArrayDepth(arrayitem.child);
  16.       }
  17.     });
  18. };
  19. console.log(Array);
  20.      
  21. 0:{
  22.   id: 1,
  23.   child: []
  24. }
  25.      
  26. 0:{
  27.   id: 1,
  28.   child: [
  29.     0:{
  30.       id: 2,
  31.       child: []
  32.     },
  33.     1:{
  34.       id: 3,
  35.       child: []
  36.     }
  37.   ]
  38. }
  39.      
  40. 0:{
  41.   id: 1,
  42.   child: [
  43.     0:{
  44.       id: 2,
  45.       child: [
  46.         0:{
  47.           id: 3,
  48.           child: []
  49.         }
  50.       ]
  51.     }
  52.   ]
  53. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top