javascript get unique items of array
function toUniqueArray(a){
var newArr = [];
for (var i = 0; i < a.length; i++) {
if (newArr.indexOf(a[i]) === -1) {
newArr.push(a[i]);
}
}
return newArr;
}
var colors = ["red","red","green","green","green"];
var colorsUnique=toUniqueArray(colors); // ["red","green"]
Also in JavaScript:
- jquery dropdown select
- js page reload
- insert element at beginning of array javascript
- settimeout inside loop
- buttons js before submit
- Jquery SEND TO START OF ARRAY
- jquery script cdn stackoverflow
- check if array has same values javascript
- for Loop continue
- vue timeout
- div non selectabel text
- javascript get index of object with value in array
- javascript how to trigger and event
- javascript access to xmlhttprequest at from origin 'null' has been blocked by cors policy
- if else jquery click function
- how to use the onload event n vue js
- what is payload in redux
- javascript function variable arguments
- javascript code for find the last element in array
- how to save thing in cookie js
- shift and unshift js
- what does json.parse do
- jquery class list
- convert int to float in javascript