Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7888085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:44:51+00:00 2026-06-03T05:44:51+00:00

Possible Duplicate: Using jQuery to compare two arrays I need a Javascript or jQuery

  • 0

Possible Duplicate:
Using jQuery to compare two arrays

I need a Javascript or jQuery function to determine if an array contains all the values of another array. The second array can have more values than the first.

This should return either true or false. For example.

comparing  array1 = [1,2,3]  and  array2 = [1,2]      should return false

comparing  array1 = [1,2,3]  and  array2 = [1,1,2]    should return false

comparing  array1 = [1,2,3]  and  array2 = [3,2,1]    should return true

comparing  array1 = [1,2,3]  and  array2 = [1,2,1,3]  should return true

Performance is not a concern. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:44:53+00:00Added an answer on June 3, 2026 at 5:44 am

    Checks each element in the first array and sees if it exists in the second array.

    NB. This is pure javascript, might be an easier way in jQuery.

    var notFound = false;
    
    for(var i = 0, len = firstArray.length; i < len; i++){
        if(secondArray.indexOf(firstArray[i]) === -1)
        {
             notFound = true;
             break;
        }
    }
    
    if(notFound)
    {
        ....
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Using jQuery to compare two arrays I have to send the form
Possible Duplicate: using jquery $.ajax to call a PHP function I need to call
Possible Duplicate: javascript: pause setTimeout(); Im using jQuery and working on a notification system
Possible Duplicate: Kill Ajax requests using JavaScript using jQuery Here is the simple code
Possible Duplicate: DOM Mutation event in JQuery or vanilla Javascript I am using backbone.js
Possible Duplicate: How would you compare jQuery objects? I'm using jQuery to store the
Possible Duplicate: How to get all options of a select using Jquery? I have
Possible Duplicate: javascript compare strings without being case sensitive. I am having two fields.
Possible Duplicate: Detect all changes to a <input type=text> (immediately) using JQuery I have
Possible Duplicate: Submit a form using jQuery $('#form') Supposed the jQuery Object of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.