
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check 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