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:
A Very Big Sum | Javascript | hackerrank07-05-2020 A Very Big Sum Javascript hackerrank |
Check null values in JavaScript?04-02-2019 JavaScript null check null value |
How to convert html to pdf in Node js12-03-2017 pdf convert html node js |
Filter for replace text in Angular Js05-03-2017 filter replace angular js |
Filters for convert text to camel case in Angular Js05-03-2017 angularjs camelcase filters |