How can I get a list of unique values in an array? Do I always have to use a second array or is there something similar to java’s hashmap in JavaScript?
I am going to be using JavaScript and jQuery only. No additional libraries can be used.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Since I went on about it in the comments for @Rocket’s answer, I may as well provide an example that uses no libraries. This requires two new prototype functions,
containsanduniqueFor more reliability, you can replace
containswith MDN’sindexOfshim and check if each element’sindexOfis equal to -1: documentation