![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Checking if a string contains all unique characters using JavaScript
Problem
We are required to write a JavaScript function that takes in a sting and returns true if all the characters in the string appear only once and false otherwise.
Example
Following is the code −
const str = 'thisconaluqe'; const allUnique = (str = '') => { for(let i = 0; i < str.length; i++){ const el = str[i]; if(str.indexOf(el) !== str.lastIndexOf(el)){ return false; }; }; return true; }; console.log(allUnique(str));
Output
true
Advertisements