
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
JavaScript Array: Checking for multiple values
We are required to write a JavaScript function that takes in two arrays of Numbers and checks whether all the elements of the first array exist in the second or not.
Example
The code for this will be −
const arr1 = [34, 78, 89]; const arr2 = [78, 67, 34, 99, 56, 89]; const multipleIncludes = (first, second) => { const indexArray = first.map(el => { return second.indexOf(el); }); return indexArray.indexOf(-1) === -1; } console.log(multipleIncludes(arr1, arr2));
Output
The output in the console −
true
- Related Questions & Answers
- Checking an array for palindromes - JavaScript
- Checking for uniqueness in an array in JavaScript
- Checking progressive array - JavaScript
- Remove same values from array containing multiple values JavaScript
- Checking for vowels in array of numbers using JavaScript
- JavaScript - Checking for pandigital numbers
- Checking for overlapping times JavaScript
- Checking for string anagrams JavaScript
- Checking for majority element in a sorted array in JavaScript
- Checking for co-prime numbers - JavaScript
- Checking for Fibonacci numbers in JavaScript
- Checking for coprime numbers in JavaScript
- Checking for ascending arrays in JavaScript
- Checking for straight lines in JavaScript
- Checking for convex polygon in JavaScript
Advertisements