blog post

Source Code

Arrays in JavaScript are daunting and particularly difficult in nature. The fundamental reason for making this statement is that JavaScript does not provide as many functions/methods for array operations as several other languages do. As a result, an array operation as simple as removing duplicate elements from an array may also be particularly intimidating. A possible approach for accomplishing this task of removing duplicate elements from an array in JavaScript is using the method reduce(). The method reduce() performs execution of the callback function for every element present in the array.

var thelist = ["ball_1", "ball_13", "ball_23", "ball_1"];

output: ["ball_1", "ball_13", "ball_23"]

function unique(list) {
    var result = [];
    $.each(list, function(i, e) {
        if ($.inArray(e, result) == -1) result.push(e);
    return result;

  • Share This Story

Pleas give your valuable comments to improve the contents.

about author

Atul kumar shukla

I'm Atul Kumar Shukla, working as a web developer.
Welcome to my Blog. This is my personal blog where i post my own questions and answers , articles about ASP.Net., SQL Server, HTML, CSS, Jquery and many more..

Visit Profile

Leave a comment


Get More Stuff
Subscribing to the TheOneblogs newsletter and get intersting stuff and updates to your email inbox.
Your Email


Style Switcher

Change Color

×! We use cookies to improve your user experience. More information