ItSolutionStuff.com

How to Get Unique Values from Array in JQuery?

By Hardik Savani • July 14, 2023
jQuery

Today, i will give you example of get unique values from json array in jquery. you will understand how to get get unique values from array in Jquery. we can easily get distinct values from array jquery.

After long time i am going to write jquery post with json array. here i decide to give you simple of getting unique values from jquery array. most of projects we need to work with json array and manage it different way.

So, here i will give you very simple example of jquery get unique values from json array with output.

Solution:

var uniqueSites = sites.filter(function(item, i, sites) {

return i == sites.indexOf(item);

});

Example:

<!DOCTYPE html>

<html>

<head>

<title>How to get unique values from array in Jquery? - ItSolutionStuff.com</title>

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>

</head>

<body>

<script type="text/javascript">

var sites = [ "ItSolutionStuff.com", "HDTuto.com", "NiceSnippets.com", "ItSolutionStuff.com" ];

var uniqueSites = sites.filter(function(item, i, sites) {

return i == sites.indexOf(item);

});

console.log(uniqueSites);

</script>

</body>

</html>

Output:

["ItSolutionStuff.com", "HDTuto.com", "NiceSnippets.com"]

I hope it can help you...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

JQuery Open Link in New Tab on Click Example

Read Now →

JQuery Open Link in New Window Example

Read Now →

How to Remove Key Value from Array using JQuery?

Read Now →

How to Convert Array to JSON in PHP?

Read Now →

How to Get Last Element from Array using JQuery?

Read Now →

JQuery Check If Value Exists or Not in Array Example

Read Now →

How to Remove Empty or Null Values from JSON using JQuery?

Read Now →

How to Check If Key Exists in JSON Object using JQuery?

Read Now →

How to Disable F5 Refresh Button using JQuery?

Read Now →

Add Edit Delete Table Row Example using JQuery

Read Now →

How to Disable Browser Back Button using JQuery?

Read Now →

How to Remove Empty or Null Values from Array in JQuery?

Read Now →

JQuery - How to Push Specific Key and Value in Array?

Read Now →

How to Parse JSON in JQuery Ajax?

Read Now →

How to Check Undefined, Empty and Null in JQuery?

Read Now →