-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
43 lines (37 loc) · 752 Bytes
/
test.js
File metadata and controls
43 lines (37 loc) · 752 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
let inputJSON = {
name: "John",
children: [
{
name: "Alice",
},
{
name: "Bob",
children: [
{
name: "Charlie",
},
],
},
],
};
function fun(obj) {
// declare variables
let hasChildrenVar = false;
let counter = 1;
// check obj has an array
function hasChildren(obj){
for (const key in obj) {
if(Array.isArray(obj[key])){
counter++;
//call function again
}
}
}
for (const key in obj) {
if(typeof obj[key] == "object"){
obj[key] = {...obj[key],id:4};
}else if(Array.isArray(obj[key])){
obj[key] = fun({...obj[key]});
}
}
}