再帰処理がしたい?
javascript
1var route = {
2 params: {
3 p1: "xxx1",
4 p2: undefined,
5 p3: "xxx1",
6 p4: "xxx1",
7 },
8 params2: {
9 p1: "xxx2",
10 p2: "xxx2",
11 p3: "xxx2",
12 p4: undefined,
13 },
14 params3: {
15 p1: "xxx3",
16 p2: "xxx3",
17 params4:[
18 "xxx4",
19 undefined,
20 "xxx4",
21 ],
22 },
23};
24function getAllValues(x){
25 var ret=[];
26 Object.entries(x).forEach(y=>{
27 if(y[1] instanceof Object){
28 ret=ret.concat(getAllValues(y[1]));
29 }else{
30 ret.push(y[1]);
31 }
32 });
33 return ret;
34}
35console.log(getAllValues(route).indexOf(undefined)>-1);
特定のkey
特定のkeyの部分がぬけてました
javascript
1var route = {
2 params: {
3 p1: "xxx1",
4 p2: undefined,
5 p3: "xxx1",
6 p4: "xxx1",
7 },
8 params2: {
9 p1: "xxx2",
10 p2: "xxx2",
11 p3: "xxx2",
12 p4: null,
13 },
14 params3: {
15 p1: "xxx3",
16 p2: "xxx3",
17 params4:[
18 "xxx4",
19 undefined,
20 "xxx4",
21 ],
22 },
23};
24
25const checkUndefined=(arr,obj)=>getAllValues(obj).filter(x=>arr.indexOf(x[0])>-1).map(x=>x[1]).indexOf(undefined)>-1;
26const getAllValues=x=>{
27 var ret=[];
28 Object.entries(x).forEach(y=>{
29 if(y[1] instanceof Object){
30 ret=ret.concat(getAllValues(y[1]));
31 }else{
32 ret.push(y);
33 }
34 });
35 return ret;
36};
37console.log(checkUndefined(["p1"],route)); //false
38console.log(checkUndefined(["p2"],route)); //true
39console.log(checkUndefined(["p1","p2"],route)); //true
40console.log(checkUndefined(["p99"],route)); //false
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。