Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· OpenAIAi2 WildChat-4.8M (AI2)

js 判断10 是否在 [11,12,13] 内

  1. User

    js 判断10 是否在 [11,12,13] 内

  2. Assistant

    可以使用 JavaScript 的 includes() 方法来判断一个元素是否在数组中。

    示例代码:

    const arr = [11, 12, 13];
    const isContained = arr.includes(10);
    console.log(isContained); // false
    

    这段代码中,我们先定义了一个数组 arr,然后使用 includes() 方法来判断数字 10 是否在数组中。由于数组中没有数字 10,所以 isContained 变量的值为 false。