[英]Push to array and compare two arrays JavaScript
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.
我在这里发现使用jQuery比较两个数组现在我尝试使用它,但是我做错了事。
This is my JSfiddle where my code is. 这是我的代码所在的JSfiddle 。 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: 这是我的代码:
<p class="wyliczanka-element">Heh</p>
<p class="wyliczanka-element">huh</p>
$(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. 谢谢你的帮助。
You are comparing two strings to two undefined variables. 您正在将两个字符串与两个未定义的变量进行比较。
var wyliczanka_wzor = [Heh, huh];
should be 应该
var wyliczanka_wzor = ['Heh', 'huh'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.