gpt4 book ai didi

javascript - jQuery 中是否有类似 array_unique() 的函数?

转载 作者:可可西里 更新时间:2023-11-01 13:10:11 24 4
gpt4 key购买 nike

<分区>

我有一个选择,我可以在其中获取一些值作为数组,如 ["1","2","3"]

在每次更改时,我都运行以下代码以获取与我从 select 获得的这些值相关联的数组结果

$('#event-courses-type').on('change',function(){

type = $('#event-courses-type').val();

console.log(type);

var var1 = ["4689 Leadership Award", "UKCC Level 1", "UKCC Level 2", "UKCC Level 3", "UKCC Level 4", "Old WHU Award", "None at present"];
var var2 = ["4689 Leadership Award", "GB-wide Level 1", "Old Level 1 (Pre January 2012)", "Level 2", "Level 3", "EHF", "FIH", "None at present"];

var var5 = ["D32/33", "A1 Assessor", "CTS", "IAPS", "PTLLS", "AVRA", "Umpire Educator Training", "Umpire Assessor Training"];
var var6 = ["D32/33", "A1 Assessor", "CTS", "IAPS", "PTLLS", "AVRA", "Umpire Educator Training", "Umpire Assessor Training"];

var results = [];

if ($.inArray("1",type) != -1) {
var results = $.merge(var1, results);
}
if ($.inArray("2",type) != -1) {
var results = $.merge(var2, results);
}
if ($.inArray("5",type) != -1) {
var results = $.merge(var5, results);
}
if ($.inArray("6",type) != -1) {
var results = $.merge(var6, results);
}

console.log(results);
)};

这是我的控制台日志,让您在我选择 2 个选项和结果数组后看到类型数组:

["1", "2"] ------------------- add_event.php:802

["4689 Leadership Award", "GB-wide Level 1", "Old Level 1 (Pre January 2012)", "Level 2", "Level 3", "EHF", "FIH", "None at present", "4689 Leadership Award", "UKCC Level 1", "UKCC Level 2", "UKCC Level 3", "UKCC Level 4", "Old WHU Award", "None at present"]

如您所见,有两次“4689 领导奖”,我不希望这种情况发生。在 PHP 中,我使用 array_unique() 函数来消除这些重复值,但我不知道如何在 jQuery 中执行此操作。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com