0

How can I remove duplicates from 10.000 elements array of strings?

I have array of strings in format:

[ '[[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0], 
[0,0,0,1,1,1,1,1,1],[0,0,0,1,1,1,1,1,1],[0,0,0,1,1,1,1,1,1], 
[0,0,0,1,1,1,0,0,0],[0,0,0,1,1,1,0,0,0],[0,0,0,1,1,1,0,0,0]]',
'[[0,0,0,1,1,1,1,1,1],[0,0,0,1,1,1,1,1,1],[0,0,0,1,1,1,1,1,1], 
[0,0,0,1,1,1,0,0,0],[0,0,0,1,1,1,0,0,0],[0,0,0,1,1,1,0,0,0], 
[0,0,0,1,1,1,0,0,0],[0,0,0,1,1,1,0,0,0],[0,0,0,1,1,1,0,0,0]]', ....]

There are 10.000 of elements in it, and after deleting duplicates it should be about 500. For now i'm using this code, but it doesnt work since "FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory" problem is poping out.

newarr = [];

for(var i = 0; i<arr.length; i++){
  var idx = arr.indexOf(arr[i])
  while (idx != 0) {
    newarr.push(idx);
    idx = arr.indexOf(wycinki[i], idx + 1);
  }    
}
2
  • What's the expected output? Commented Jul 25, 2018 at 13:00
  • @3piy array of Strings without duplicates Commented Jul 25, 2018 at 13:04

1 Answer 1

5

A one-liner that can do it utilizes the Javascript Set class.

Array.from(new Set(arr));

This code will return an array of all unique strings.

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

1 Comment

very elegant solution

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.