-1

I have two arrays of objects. I need to check if items are contained in another array. If one of them is not contain will be false.

 const arr = [
            {full_name: 'Test'},
            {full_name: 'Test1'},
            {full_name: 'Test2'},
        ]

        const arr1 = [
            {full_name: 'Test'},
            {full_name: 'Test1'},
            {full_name: 'Test2'},
            {full_name: 'Test3'},
            {full_name: 'Test4'},
            {full_name: 'Test5'},
            {full_name: 'Test6'},
        ]

If arr1 contain Test Test1 Test2 will be true, if one of them not contains will be false.

I think I need some operator

1
  • Try searching for duplicate questions. Commented Oct 30, 2019 at 14:15

1 Answer 1

0

My approach using every and some array functions:

const arr = [
    {full_name: 'Test'},
    {full_name: 'Test1'},
    {full_name: 'Test6'},
]

const arr1 = [
    {full_name: 'Test'},
    {full_name: 'Test1'},
    {full_name: 'Test2'},
    {full_name: 'Test3'},
    {full_name: 'Test4'},
    {full_name: 'Test5'},
    {full_name: 'Test6'},
]

console.log(arr.every(item => {
  return arr1.some( i2 => i2.full_name == item.full_name)
}))

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.