Get Unique values from array/object in javascript

javascript
unique
remove repeated values from array

Here is the sample array

var Obj = [1,3,4,2,1,2,3,8];
var Obj = Obj.unique();

Result is

[1,3,4,2,8]

Add thease below lines in your script tag. The below code is remove duplicates from array/object

Array.prototype.contains = function(v) {
    for(var i = 0; i < this.length; i++) {
        if(this[i] === v) return true;
    }
    return false;
};

Array.prototype.unique = function() {
    var arr = [];
    for(var i = 0; i < this.length; i++) {
        if(!arr.contains(this[i])) {
            arr.push(this[i]);
        }
    }
    return arr; 
};

 

You might also like:

How To Get Your Blogs Posts Using Blogger API

30-07-2017 blogger api json php

How to make an http request in node js

14-03-2017 http module node js

How to get current date and time (yyyy-mm-dd H:i:s) using javascript

09-03-2017 javascript date time

Using slice remove last two characters from given string

07-03-2017 slice remove

How to change background color and color to the text using javascript

27-02-2017 css javascript colors