Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript array includes another array

const array1= ["cheese", "dough", "sauce", "pepperoni"]
const array2= ["mozzarella", "peppers", "chicken", "cheese"]

const isIncluded =  array1.some(value => array2.includes(value))
// true

const values = array1.filter(value => array2.includes(value))
// "cheese"
Comment

javascript check if elements of one array are in another

const found = arr1.some(r=> arr2.includes(r))
Comment

How to check if array includes a value from another array in JavaScript

// How to check if array includes a value from another array in JavaScript
const includesAny = (arr, values) => values.some(v => arr.includes(v));
includesAny([1, 2, 3, 4], [2, 9]); // true
includesAny([1, 2, 3, 4], [8, 9]); // false
Comment

how to check all elements in array includes in another array javascript

// how to check all elements in array includes in another array javascript
const includesAll = (arr, values) => values.every(v => arr.includes(v));
includesAll([1, 2, 3, 4], [1, 4]); // true
includesAll([1, 2, 3, 4], [1, 5]); // false
Comment

if array ontains any item of another array js

const found = arr1.some(r=> arr2.indexOf(r) >= 0)
Comment

find items in array not in another array javascript

var arr1 = [
    {
      "prop1": "value1",
      "prop2": "value2",
    },
    {
      "prop1": "value3",
      "prop2": "value4",
    },
    {
      "prop1": "value5",
      "prop2": "value6",
    },
  ];

var arr2 = ['value1','value3', 'newValue'];

// finds all the elements of arr2 that are not in arr1
arr2.filter( 
    val => !arr1.find( arr1Obj => arr1Obj.prop1 === val)
); // outputs "newValue"
Comment

PREVIOUS NEXT
Code Example
Javascript :: Extract phone number from text regex 
Javascript :: split sentence in array js 
Javascript :: 3 letter months javascript array 
Javascript :: unrecognized font family fontawesome react native ios 
Javascript :: font ligature vs code 
Javascript :: await useeffect react 
Javascript :: mongoose virtuals 
Javascript :: Properly upgrade node using nvm 
Javascript :: javascript round to 1 decimal 
Javascript :: jquery focus 
Javascript :: Getting Binary gap in JS 
Javascript :: javascript sort array by object property 
Javascript :: jquery find previous element with class 
Javascript :: react native text get number of lines 
Javascript :: javascript remove single class from element 
Javascript :: remove duplicates from array 
Javascript :: count a character in a string, js 
Javascript :: How to call a c# functio from Javascript 
Javascript :: last element in javascript 
Javascript :: create react portal 
Javascript :: disable global require eslint 
Javascript :: reactive forms change event in angular 
Javascript :: Fibonacci Series Program. in javascript 
Javascript :: how to append values to dropdown using jquery 
Javascript :: angular add a new line from component 
Javascript :: what 1hr in milliseconds in javascript 
Javascript :: mac node change version 16 
Javascript :: momentjs range 
Javascript :: fetch data from asyncstorage react native 
Javascript :: heroku scripts 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =