Home > front end >  How to determine whether to include this element in the array
How to determine whether to include this element in the array

Time:03-02

Var test=[1, 2, 3]
$. InArray (1, test);
That is able to judge the test have 1 this element in the array, but I'm a but for complex data not
Var test=[];
Info={js: 0, name: 'aa', url: "https://123.html"};
Test. Push (info);
$. InArray (info, test);
So I can't find it, the returned have been 1,
how to change?

CodePudding user response:

Change
Var=b test. Some (e=& gt; JSON. Stringify (e) equals (JSON. Stringify (info));
The console. The log (b);//if found is true, can't find is false

CodePudding user response:

Problem has been to help you solve, the problem is js Array

CodePudding user response:

reference 1st floor qybao response:
change
Var=b test. Some (e=& gt; JSON. Stringify (e) equals (JSON. Stringify (info));
The console. The log (b);//if found is true, can't find is false


An error
JSON. Stringify (... .) the equals is not a function

CodePudding user response:

Everyone will not answer, I will give you the answer, copy js code can solve the problem of you
 & lt; ! DOCTYPE html> 



<meta charset="utf-8" & gt;
<meta name="viewport" content="initial - scale=1.0, the maximum - scale=1.0, user - scalable=no"/& gt;
How to determine whether to include this element in the array xinbiancheng. Cn


<body>
Easy to solve how to determine whether to include this element in the array

<script>
Var test=[];
Info={js: 0, name: 'aa', url: "https://123.html"};
Test. Push (info);
Var b=test. Includes (info);
The console. The log (b)
</script>

  • Related