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:
Functions in javascript25-05-2018 functions javascript es5 es6 arrow functions named functions Closures Nested Functions Callbacks Arrow functions. |
How to insert bulk information into database in single query execution18-03-2017 insert sql bulk database |
Filter for change Date format (MM-dd-yyyy) in Angular Js05-03-2017 mm-dd-yyyy date formats angular js |
How to remove last / value from url in javascript27-02-2017 array javascript last value |
Call a function every second or 5 seconds in javascript22-02-2017 setinterval function calling |