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 7828119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:12:43+00:00 2026-06-02T10:12:43+00:00

I have an array with nested arrays that looks like this: var tw =

  • 0

I have an array with nested arrays that looks like this:

var tw = [[3, 0], [11, 0], [3, 14], [11, 14]];

When I try and find if the array tw contains a passed in array, I always get a result of -1.

For example:

var test = $.inArray([3, 0], tw);
var test2 = tw.indexOf([3, 0]);

both return -1, even though the first object in the array is [3,0]
How do I find out if a specific array of arrays is contained in my array?

Oh, and I’ve only tested it on IE9 so far.

  • 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-02T10:12:45+00:00Added an answer on June 2, 2026 at 10:12 am

    That’s because you’re searching for a different object. indexOf() uses strict equality comparisons (like the === operator) and [3, 0] === [3, 0] returns false.

    You’ll need to search manually. Here’s an example using a more generic indexOf() function that uses a custom comparer function (with an improvement suggested by @ajax333221 in the comments):

    // Shallow array comparer
    function arraysIdentical(arr1, arr2) {
        var i = arr1.length;
        if (i !== arr2.length) {
            return false;
        }
        while (i--) {
            if (arr1[i] !== arr2[i]) {
                return false;
            }
        }
        return true;
    }
    
    function indexOf(arr, val, comparer) {
        for (var i = 0, len = arr.length; i < len; ++i) {
            if ( i in arr && comparer(arr[i], val) ) {
                return i;
            }
        }
        return -1;
    }
    
    var tw = [[3, 0], [11, 0], [3, 14], [11, 14]];
    alert( indexOf(tw, [3, 0], arraysIdentical) ); // Alerts 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a nested array that looks like this: @nested = [ ['1','2','3'], ['1','5','9'],
I have a hierarchically nested associative array. It looks like this: A = {
I have a 2D array that looks like this: array(2) { [45]=> array(5) {
I have an array that looks like this except with over 40 more Array
I have code that looks like this: function foobar(array& $objects, $con = null) {
I have an array that looks like this: Array ( [0] => Array (
I have a nested associative array like this: $inputTypes= array( natural => array( text,
I have an array which looks like this $dataArray = array ( 0 =>
I have an Entity that looks like this: class Privilege { /** * @Id
Let's say I have a table called my_table that looks like this: id |

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.