Use reduce for getting the result.

var arr = [["apple","ghana",15],["apple","brazil",16],["orange","nigeria",10],["banana","bangladesh",20],["banana","ghana",6]];

const res = arr.reduce((a, c) => {
	if (!a.find(v => v[0] === c[0])) {
		a.push(c);
	}
	return a;
}, []);

console.log(res);
.as-console-wrapper {
  min-height: 100% !important;
  top: 0;
}

Answer from Sajeeb Ahamed on Stack Overflow
🌐
Blogger
sunnybahree.blogspot.com β€Ί 2016 β€Ί 01 β€Ί how-to-get-unique-items-or-values-from_14.html
Sunny Bahree: How to get unique items or values from Multidimensional Array or an Object JQuery
In this post, I will demonstrate how to get unique values from multidimensional array using JQuery. Basic knowledge of JQuery - To know more about the same, please see this site https://jquery.com/ CDN Reference of JQuery library which will be used in our JQuery script - JQuery CDN latest Stable Versions can be found here https://code.jquery.com/ Knowledge of Javascript/JQuery Arrays - To learn or know more about Arrays, please see this site http://www.w3schools.com/js/js_arrays.asp
Discussions

How to get only unique items in a multidimensional array with JavaScript/jquery? - Stack Overflow
I got for example a multidimensional array items with 2 dimensions. I get this array from a database, but it will fill up to 2600+ objects, but if i could some how unique this it would be around 30 More on stackoverflow.com
🌐 stackoverflow.com
May 23, 2017
javascript - Find a unique item based on two values in multi-dimensional array - Stack Overflow
I have an array called collection. This array contains a large number of arrays with a length of 12. Each item of the latter array has - among others - a source ID [0] and target ID [1] (pairs of s... More on stackoverflow.com
🌐 stackoverflow.com
June 14, 2013
jquery - Unique value in multidimentional array in javascript - Stack Overflow
Communities for your favorite technologies. Explore all Collectives Β· Ask questions, find answers and collaborate at work with Stack Overflow for Teams More on stackoverflow.com
🌐 stackoverflow.com
javascript - How to Count Unique Arrays in a Multidimensional Array - Stack Overflow
While reducing, you can check whether ... and then increment it by 1 (which acts as the default value for any new keys (i.e newly seen arrays)). Lastly, you can get the keys from your object which represent each unique array as strings using Object.keys(), and parse each back into ... More on stackoverflow.com
🌐 stackoverflow.com
September 9, 2019
🌐
Wikitechy
wikitechy.com β€Ί tutorials β€Ί javascript β€Ί unique-values-in-an-array
javascript tutorial - Unique values in an array - By Microsoft Award MVP - Learn in 30sec javascript - java script | wikitechy
To get an array with unique values we could do now this: var myArray = ['a', 1, 'a', 2, '1']; let unique = [...new Set(myArray)]; // unique is ['a', 1, 2, '1'] ... The constructor of Set takes an iterable object, like Array, and the spread operator ... transform the set back into an Array.
🌐
CoreUI
coreui.io β€Ί blog β€Ί how-to-get-unique-values-from-a-javascript-array
How to Get Unique Values from a JavaScript Array Β· CoreUI
July 5, 2024 - The most efficient way to get unique values from an array is by using the Set object along with the spread operator. This method is concise and leverages ES6 features: const array = [1, 2, 2, 3, 4, 4, 5] const uniqueArray = [...new Set(array)] ...
🌐
Medium
medium.com β€Ί @robert.roksela β€Ί 6-ways-to-remove-duplicates-from-an-array-in-javascript-es6-syntax-88cb3750a986
6 ways to remove duplicates from an Array in JavaScript / ES6 Syntax | by Robert Roksela | Medium
September 30, 2020 - If it’s true then it returns only the accumulator, if it’s false it returns the accumulator, which is expanded to a new array using spreading operator (…), and adds the β€˜nextItem’ to the new array. Everything is assigned to a new variable. ... For … of, similarly to forEach presented in this article, loops though all values of the β€˜basedArray’ pushing unique elements to the freshly declared β€˜targetArray’, which is outside of the loop.
🌐
Stack Overflow
stackoverflow.com β€Ί questions β€Ί 20355058 β€Ί how-to-get-only-unique-items-in-a-multidimensional-array-with-javascript-jquery
How to get only unique items in a multidimensional array with JavaScript/jquery? - Stack Overflow
May 23, 2017 - You're making a mistake in pushing them onto an array in the first place. You should be creating an associative array, with the key field the unique aspect.
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί how-to-get-all-unique-values-remove-duplicates-in-a-javascript-array
JavaScript – Unique Values (remove duplicates) in an Array | GeeksforGeeks
November 14, 2024 - These are the following methods to get all non-unique values from an array:Table of ContentUsing Array Slice() MethodUsing for loopUsin ... In JavaScript, arrays are the object using the index as the key of values. In this article, let us see how we can filter out all the non-unique values and in return get all the unique and non-repeating elements.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί javascript β€Ί how-to-get-all-unique-values-remove-duplicates-in-a-javascript-array
JavaScript - Unique Values (remove duplicates) in an Array - GeeksforGeeks
July 11, 2025 - // Given array let a = [10, 20, ... } } // Display updated array console.log("Updated Array: ", a1); ... The array.filter() method is used to create a new array from an existing array consisting of only those elements ...
🌐
Stack Overflow
stackoverflow.com β€Ί questions β€Ί 41467513 β€Ί unique-value-in-multidimentional-array-in-javascript
jquery - Unique value in multidimentional array in javascript - Stack Overflow
My question is, how can I get just the unique element (value), I write a code like this, but not give me that I need; var unique = init.filter(function(item,i, a){ return i==a.indexOf(item); }); ... [ Object { label=" Login ", value="Create ...
Top answer
1 of 2
2

You can map each inner array to a stringified version of itself using .map(JSON.stringified). Now, using this new array, you can reduce it to an object which contains each stringified array as a key, and keeps the number of occurrences as its value. While reducing, you can check whether or not the object's key has already been set using a[k] = (a[k] || 0)+1. If it has already been set, it will use the current number stored at the key and increment it by 1, if it hasn't already been set it will set it equal to zero, and then increment it by 1 (which acts as the default value for any new keys (i.e newly seen arrays)).

Lastly, you can get the keys from your object which represent each unique array as strings using Object.keys(), and parse each back into a non-stringified array using JSON.parse. You can get the counts from your array by using Object.values() as this will get all the values (ie: the counters) of your reduced object and put them into an array.

See example below:

const arr = [[1,2], [1,2], [1,3], [1,4], [1,4], [1,4]]; 

const arr_str = arr.map(JSON.stringify);
const arr_map = arr_str.reduce((a, k) => (a[k] = (a[k] || 0) + 1, a), {});
const uniqueArrays = Array.from(Object.keys(arr_map), JSON.parse);
const theCount = Object.values(arr_map);

console.log(uniqueArrays);
console.log(theCount);

2 of 2
1

you can use below code

var arr = [[1,2], [1,2], [1,3], [1,4], [1,4], [1,4]]; 
var uniqueArrays = []; 
var theCount = [];
var test = [], obj ={};
arr.forEach(val => {
    if(test.indexOf(val.toString()) == -1){
        test.push(val.toString());
        obj[val.toString()] = 1;
        uniqueArrays.push(val);
    }else{
        obj[val.toString()] += 1;

    }

})
theCount = Object.values(obj);
console.log(uniqueArrays);
console.log(theCount);

Hope it will help you.

Top answer
1 of 16
445

Here's a much cleaner solution for ES6 that I see isn't included here. It uses the Set and the spread operator: ...

var a = [1, 1, 2];

[... new Set(a)]

Which returns [1, 2]

2 of 16
302

Or for those looking for a one-liner (simple and functional) compatible with current browsers:

let a = ["1", "1", "2", "3", "3", "1"];
let unique = a.filter((item, i, ar) => ar.indexOf(item) === i);
console.log(unique);
Run code snippetEdit code snippet Hide Results Copy to answer Expand

Update 2021 I would recommend checking out Charles Clayton's answer, as of recent changes to JS there are even more concise ways to do this.

Update 18-04-2017

It appears as though 'Array.prototype.includes' now has widespread support in the latest versions of the mainline browsers (compatibility)

Update 29-07-2015:

There are plans in the works for browsers to support a standardized 'Array.prototype.includes' method, which although does not directly answer this question; is often related.

Usage:

["1", "1", "2", "3", "3", "1"].includes("2");     // true

Pollyfill (browser support, source from mozilla):

// https://tc39.github.io/ecma262/#sec-array.prototype.includes
if (!Array.prototype.includes) {
  Object.defineProperty(Array.prototype, 'includes', {
    value: function(searchElement, fromIndex) {

      // 1. Let O be ? ToObject(this value).
      if (this == null) {
        throw new TypeError('"this" is null or not defined');
      }

      var o = Object(this);

      // 2. Let len be ? ToLength(? Get(O, "length")).
      var len = o.length >>> 0;

      // 3. If len is 0, return false.
      if (len === 0) {
        return false;
      }

      // 4. Let n be ? ToInteger(fromIndex).
      //    (If fromIndex is undefined, this step produces the value 0.)
      var n = fromIndex | 0;

      // 5. If n β‰₯ 0, then
      //  a. Let k be n.
      // 6. Else n < 0,
      //  a. Let k be len + n.
      //  b. If k < 0, let k be 0.
      var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);

      // 7. Repeat, while k < len
      while (k < len) {
        // a. Let elementK be the result of ? Get(O, ! ToString(k)).
        // b. If SameValueZero(searchElement, elementK) is true, return true.
        // c. Increase k by 1.
        // NOTE: === provides the correct "SameValueZero" comparison needed here.
        if (o[k] === searchElement) {
          return true;
        }
        k++;
      }

      // 8. Return false
      return false;
    }
  });
}
🌐
Appdividend
appdividend.com β€Ί 2022 β€Ί 06 β€Ί 04 β€Ί how-to-get-distinct-values-from-array-in-javascript
Getting Unique Values (Remove Duplicates) in an Array in JavaScript
November 7, 2025 - Here are five ways to get all unique values from an array in JavaScript : Using new Set() constructor ,Using filter() + indexOf() methods ,Using filter() method , Using Set and Array.from() a method and Defining custom Array Unique Prototype
🌐
DEV Community
dev.to β€Ί phibya β€Ί methods-to-get-unique-values-from-arrays-in-javascript-and-their-performance-1da8
Methods to get unique values from arrays in Javascript and their performance - DEV Community
February 21, 2022 - It is clear that the more duplication we have in the array, the faster the code runs. It is also obvious that using Array.prototype.reduce and Set is the fastest among all. Bonus: Getting unique values from an array of objects using multiple-level object keys (nested properties):
🌐
Zipy
zipy.ai β€Ί blog β€Ί how-do-i-get-all-of-the-unique-values-in-a-javascript-array-remove-duplicates
how do i get all of the unique values in a javascript array remove duplicates
April 12, 2024 - The reduce() method executes a reducer function on each element of the array, resulting in a single output value. By combining it with includes(), we can efficiently accumulate unique values.
🌐
GitHub
gist.github.com β€Ί f4ac657e5d28e060c791f5ef27b13341
Javascript: Remove duplicates of multidimensional array Β· GitHub
Javascript: Remove duplicates of multidimensional array - remove_duplicates_array_multi.js
🌐
GitHub
gist.github.com β€Ί mojaray2k β€Ί 36eea185fc2b4c9cced12bb30b3d74b0
3 Ways to get unique values from an array in Javascript Β· GitHub
const someArray = ['😁', 'πŸ’€', 'πŸ’€', 'πŸ’©', 'πŸ’™', '😁', 'πŸ’™']; const getUniqueValues = (array) => ( array.filter((currentValue, index, arr) => ( arr.indexOf(currentValue) === index )) ) console.log(getUniqueValues(someArray)) // Result ["😁", "πŸ’€", "πŸ’©", "πŸ’™"]