Hello mates once again,
I try to compare two arrays and do something if they have same components or not. I found here this Using jQuery to compare two arrays Now i try to use it but obvusly im doing something wrong.
This is my JSfiddle where my code is. I put there two alerts to watch my code but it seems there is something wrong with pushing elements to array?
Here is my code:
HTML
<p class="wyliczanka-element">Heh</p>
<p class="wyliczanka-element">huh</p>
JavaScript
$(document).ready(function () {
var wyliczanka_wzor = [Heh, huh];
var wyliczanka = [];
$('.wyliczanka-element').each(function (i) {
wyliczanka.push($(this).text());
});
alert(wyliczanka[0]);
if (($(wyliczanka_wzor).not(wyliczanka).length === 0) && ($(wyliczanka).not(wyliczanka_wzor).length === 0)) {
alert("Youp!");
} else {
alert("meh");
}
});
Thanks for any help.
.not()function isn't intended for comparing arrays of strings. What do you expect this:var wyliczanka_wzor = [Heh, huh];to do? You don't have variablesHehandhuh, so that line will give youReferenceError: Heh is not defined- should it be... ["Heh", "huh"]?JSON.stringify( wyliczanka_wzor ) == JSON.stringify( wyliczanka ). or try lodash.com/docs#isEqual