JavaScript Removing duplicate sub-arrays remove duplicate arrays javascript,remove duplicate arrays,remove duplicate arrays

I have an array as such: [[1,3],[2,5],[1,3],[2,5]] and i would like to remove any duplicate sub-arrays. I tried using this code:

 uniqueArray = array.filter(function(item, pos) {
   return array.indexOf(item) == pos;   });

It still returns true for all the cases.

Which function can i use to get the desired result.

Answer:1

Conver the 2D array into 1D array with stringified elements

Then put then into a Set to automatically filter out the repeating elements

Now convert the Set back to an array and map the array by JSON parsing each element to restore back the arrays.

Readable and no nested loops.

const arr = [[1,3],[2,5],[1,3],[2,5]];

const setArray = new Set(arr.map(x => JSON.stringify(x)))

const uniqArray = [...setArray].map(x => JSON.parse(x))

console.log(uniqArray)
Answer:2

I have following code in my javascript var _csrf = $("#csrf_token").val(); var xhr = $.ajax ({ url : 'http://ip.jsontest.com/', type : 'GET', contentType ...

I have following code in my javascript var _csrf = $("#csrf_token").val(); var xhr = $.ajax ({ url : 'http://ip.jsontest.com/', type : 'GET', contentType ...

  1. error ajax call
  2. error ajax call jquery
  3. ajax error call function
  4. error ajax request failed
  5. error ajax request
  6. error ajax request failed joomla
  7. cors error ajax call
  8. error during ajax call
  9. error 500 ajax call
  10. 400 error ajax call
  11. get error ajax call
  12. error message ajax call
  13. 415 error ajax call
  14. success error ajax call
  15. error handling ajax call
  16. 404 error ajax call
  17. catch error ajax call
  18. return error ajax call
  19. ajax error request entity too large
  20. ajax error request object

I'm trying to run this jestJS unit-test, but I do get TypeError: Promise resolver undefined is not a function. What am I doing wrong? it('_onSubmit() should throw error if data is missing', (done) =&...

I'm trying to run this jestJS unit-test, but I do get TypeError: Promise resolver undefined is not a function. What am I doing wrong? it('_onSubmit() should throw error if data is missing', (done) =&...

  1. promise resolver is not a function

I need to use a google projects service account to access google API using JavaScript. In order to do this I need to OAuth2 to google API servers to get an auth token. I understand that Google ...

I need to use a google projects service account to access google API using JavaScript. In order to do this I need to OAuth2 to google API servers to get an auth token. I understand that Google ...

  1. retrieve service account password
  2. cannot retrieve service account
  3. retrieve windows service account password
  4. cannot retrieve service account openshift
  5. retrieve managed service account password
  6. openshift build cannot retrieve service account

Consider a radiobutton HTML element in an angular application, <div class="radio"> <label> <input type="radio" name="approvedeny" value="true" [(ngModel)]=_approvedOrDenied&...

Consider a radiobutton HTML element in an angular application, <div class="radio"> <label> <input type="radio" name="approvedeny" value="true" [(ngModel)]=_approvedOrDenied&...