• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
JavaScriptSource

JavaScriptSource

Search 5,000+ Free JavaScript Snippets

  • Home
  • Browse Snippets
    • Addon
    • Ajax
    • Buttons
    • Cookies
    • CSS
    • Featured
    • Forms
    • Games
    • Generators
    • Image Effects
    • Math Related
    • Miscellaneous
    • Multimedia
    • Navigation
    • Page Details
    • Passwords
    • Text Effects
    • Time & Date
    • User Details
Home / Miscellaneous / Check if at least one element of values is included in arr

Check if at least one element of values is included in arr

Check if at least one element of values is included in arr

Use Array.prototype.some() and Array.prototype.includes() to check if at least one element of values is included in arr.

const includesAny = (arr, values) => values.some(v => arr.includes(v));

// Examples
includesAny([1, 2, 3, 4], [2, 9]); // true
includesAny([1, 2, 3, 4], [8, 9]); // false

Source

https://www.30secondsofcode.org/js/s/includes-any

Miscellaneous

Related Snippets:

  • Assign keys to an object with the same name
  • Count the occurrences of a value in an array
  • Find last n matches
  • Capture the right click event with JavaScript

Primary Sidebar

Popular Posts

Story Generator

IP Grabber – get a users IP address with JavaScript

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2025 JavaScriptSource.com

  • About
  • Privacy Policy
  • FAQ
  • Jobs For Developers