Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement