if 语句匹配数组中的内容?

if statement to match what is in array?

我构建了一个函数来测试数组是否为空,如果是,它将唯一的对象设置为 "not available",这是用于输出到 HTML 元素,而不是他们是空的。

function checkNull(input){
    if (input === null || input === undefined || input === false || input === '' || input === ' ' || input.length === 0){
        $input = ["(not available)"];
    }
    else{
        $input = input;
    }
    return $input;
}

如果图像 url 数组恰好是空的,它的设置如上,那么我如何测试匹配数组是否等于我设置的数组?

这是我试过的;

function checkGallery($gameImageUrls){
    console.log($gameImageUrls);
    if ($gameImageUrls === ["(not available)"]){
        $('#gallery').addClass('hidden');    
    }
    else{
        generateGallery($gameImageUrls);
    }
}

这是 console.log 显示的内容:

["(not available)"]

也试过了;

    if ($gameImageUrls === '["(not available)"]'){
    if ($gameImageUrls === "(not available)"){
    if ($gameImageUrls === '"(not available)"'){

我认为,您需要检查数组中的第一个元素,如下所示:

$gameImageUrls[0] === "(not available)"