Javascript cannot directly use == or == to determine whether two arrays are equal, whether they are equal or inconsistent, and the following two lines of JS code will return false
<script type="text/javascript"> alert([]==[]); alert([]===[]);</script>
To determine whether two arrays in JS are the same, you need to convert the array into a string before comparing it. The following two lines of code will return true
<script type="text/javascript"> alert([].toString()== [].toString()); alert([].toString()===[].toString());</script>
JS needs to compare whether two arrays have the same elements, that is, all elements of the two arrays are the same, but the order of elements may not be the same. It only needs to sort the array first and then compare whether the two arrays are equal.
<script type="text/javascript"> alert([1,2,3].toString()== [3,2,1].toString()); alert([1,2,3].sort().toString()== [3,2,1].sort().toString());</script>
In addition, if [null] is used to judge, you can also return true by [null].toString() === ''.
The above comparative analysis of arrays under AngularJS is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.