Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Array = [
- { id: 1, child:[] }
- ]
- handleArrayDepth = (Array) => {
- Array.map(arrayitem => {
- let id = array.id;
- id++;
- arrayitem.child.push({
- id: id,
- child: []
- });
- if (id < 2) {
- this.handleArrayDepth(arrayitem.child);
- }
- });
- };
- console.log(Array);
- 0:{
- id: 1,
- child: []
- }
- 0:{
- id: 1,
- child: [
- 0:{
- id: 2,
- child: []
- },
- 1:{
- id: 3,
- child: []
- }
- ]
- }
- 0:{
- id: 1,
- child: [
- 0:{
- id: 2,
- child: [
- 0:{
- id: 3,
- child: []
- }
- ]
- }
- ]
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement