0
var arr = ["THYROID","CARDIAC","CARDIAC,DIABETES","METABOLIC,ARTHRITIS","RENAL DISEASES,DIABETES","LIVER DISEASES,HEPATITIS","LIVER DISEASES,CANCER,METABOLIC","LIVER DISEASES,HEPATITIS,ARTHRITIS,METABOLIC"]

Above is my Code, I need to fetch unique Values from this array using Javascript.

Like, what i expect is: If i ask for Unique Values , it should get me :

var arr = ["THYROID","CARDIAC","DIABETES","METABOLIC","RENAL DISEASES","LIVER DISEASES,"CANCER",ARTHRITIS","HEPATITIS"]
0

1 Answer 1

1

If you have an array of strings, you can just create an object using those strings as keys, then get the keys from that object.

Create the object

for (var t = {}, i = 0; i < arr.length; i++) 
  t[arr[i]] = 0;

Create an array from the objects keys

// Modern browsers only
arr = Object.keys(t);

// In older browsers you can use the polyfill from the link below,
// or just loop through the object like this:
arr = [];
for (var k in t)
  arr.push(k);

Object.keys

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.