In AngularJS, compare whether two arrays are the same and angularjs two arrays.
Javascript cannot directly use = OR = to determine whether two arrays are equal, no matter whether they are equal or full, the following two lines of JS Code will return false
<Script type = "text/javascript"> alert ([] = []); alert ([] = []); </script>
To determine whether the two arrays in JS are the same, you need to convert the array to a string before comparison. The following two lines of code 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 in the two arrays are the same, but the order of elements is not necessarily the same. You only need 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 for determination, [null]. toString () = ''is also returned.
The above section shows you how to compare the two arrays in AngularJS. I hope it will be helpful to you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!