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:
Simple Array Sum | Javascript | hackerrank.com07-05-2020 hackerrank.com javascript arrays array sum |
Use java script file client side and server side at a time in node js30-07-2017 node js include call javascript |
How to find Angular Errors06-03-2017 errors angularjs exceptionHandler |
Filter for change Date Time format (MM-dd-yyyy HH:mm) in Angular Js05-03-2017 mm-dd-yyyy HH:MM date formats angular js |
Sample Validations in javascript22-02-2017 validations javascript |