5 examples of 'javascript unique array of objects' in JavaScript

Every line of 'javascript unique array of objects' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
23function unique(array){
24 var o = {};
25 for(var i=0; i
33function unique (array) {
34 var res = []
35
36 for(var i = 0,iL = array.length;i < iL;i++) {
37 var current = array[i]
38 if(res.indexOf(current) === -1) {
39 res.push(current)
40 }
41 }
42
43 return res
44}
19function unique(array) {
20 var n = -1;
21
22 while (++n < array.length) {
23 remove(array, array[n], n);
24 }
25
26 return array;
27}
104function arrayUniqueTest() {
105 // var target = [1, 2, 3, 3, '3', '3', 'length', '__proto__', 'prototype', true, false, true, {}, {}, null, null];
106 var target = [1, 2, 3, 3, '3', '3', '__proto__', '__proto__', '__proto__', 'prototype', 'prototype', true, false, true, {}, {}, null, null];
107 // var target = [1, '1', true, 'true'];
108 console.log('\narrayUnique test:\n', arrayUnique(target));
109}
103function arrayUnique(array) {
104 const a = array.concat();
105 for (let i = 0; i < a.length; ++i) {
106 for (let j = i + 1; j < a.length; ++j) {
107 if (a[i] === a[j]) {
108 a.splice(j--, 1);
109 }
110 }
111 }
112 return a;
113}

Related snippets