
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Get values that are not present in another array in JavaScript
We are given two arrays: (arr1 and arr2) −
arr1 contains some literal values.
arr2 contains objects that map some literal values.
We are required to write a JavaScript function that takes in two such arrays. Then the function should return an array of all the elements from arr1 that are not mapped by objects in arr2.
Example
The code for this will be −
const arr1 = [111, 222, 333, 444]; const arr2 = [ { identifier: 111 }, { identifier: 222 }, { identifier: 444 }, ]; const getAbsentValues = (arr1, arr2) => { let res = []; res = arr1.filter(el => { return !arr2.find(obj => { return el === obj.identifier; }); }); return res; }; console.log(getAbsentValues(arr1, arr2));
Output
The output in the console −
[ 333 ]
- Related Articles
- Returning array values that are not odd in JavaScript
- Elements of an array that are not divisible by any element of another array in C++
- Make an array of another array's duplicate values in JavaScript
- Finding the smallest positive integer not present in an array in JavaScript
- How to search an array for values present in another array and output the indexes of values found into a new array in MongoDB?
- Compare two arrays and get those values that did not match JavaScript
- Get only specific values in an array of objects in JavaScript?
- How to get all unique values in a JavaScript array?
- How to get the most common values in array: JavaScript ?
- Get the max n values from an array in JavaScript
- Frequency of elements of one array that appear in another array using JavaScript
- Program to check all 1s are present one after another or not in Python
- Get range of months from array based on another array JavaScript
- C++ Permutation of an Array that has Smaller Values from Another Array
- Find elements which are present in first array and not in second in C++

Advertisements