- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to check whether multiple values exist within a JavaScript array
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.
Following are our arrays −
const arr1 = [34, 78, 89]; const arr2 = [78, 67, 34, 99, 56, 89];
Let's write the code and check for multiple values −
Example
const arr1 = [34, 78, 89]; const arr2 = [78, 67, 34, 99, 56, 89]; const contains = (first, second) => { const indexArray = first.map(el => { return second.indexOf(el); }); return indexArray.indexOf(-1) === -1; } console.log(contains(arr1, arr2));
Output
The output in the console will be −
true
- Related Articles
- How to check whether a particular key exist in javascript object or array?
- How to check whether a key exist in JavaScript object or not?
- How to check whether a stored procedure exist in MySQL?
- How to check whether an array is a true array in JavaScript?
- MySQL query to check if multiple rows exist?
- How to find elements of JavaScript array by multiple values?
- How to check whether an array is a subset of another array using JavaScript?
- JavaScript Array: Checking for multiple values
- How to check if multiple strings exist in another string in Python?
- JavaScript: How to check whether an array includes a particular value or not?
- Sum similar numeric values within array of objects - JavaScript
- Remove same values from array containing multiple values JavaScript
- Check whether field exist in MongoDB or not?
- How to check if an array contains integer values in JavaScript ?
- Check if given multiple keys exist in a dictionary in Python

Advertisements