0

I need to remove any duplicated parameters if exists to be written one time in URL

e.g

http://localhost:4200/res/?someName1=%D8%A7%D9%84%D8%B9%D9%8A%D9%88%D9%86&somethingName2=specialities%3D49__name%3D%D8%A7%D9%84%D8%B9%D9%8A%D9%88%D9%86&back_spec_title=Eye&back_spec_title=Eye&back_spec_id=17555&back_spec_id=17555&back_sur_title=Lasik&back_sur_title=Lasik&back_sur_id=599&back_sur_id=599&screen_type=surgery

as you can see :

back_spec_title=Eye 
back_spec_id=17555
back_sur_title=Lasik
back_sur_id=599

every parameter of those repeated two times

Desired output :

http://localhost:4200/res/?someName1=%D8%A7%D9%84%D8%B9%D9%8A%D9%88%D9%86&somethingName2=specialities%3D49__name%3D%D8%A7%D9%84%D8%B9%D9%8A%D9%88%D9%86&back_spec_title=Eye&back_spec_id=17555&back_sur_title=Lasik&back_sur_id=599&screen_type=surgery
Useme Alehosaini
  • 2,998
  • 6
  • 18
  • 26
angtesters
  • 13
  • 1
  • 5
  • How do you build out the url? – Alexander Staroselsky Dec 22 '20 at 20:37
  • i'm using `router navigate` for testing .. but in real world those parameters from laravel backend . – angtesters Dec 22 '20 at 20:39
  • 1
    Feels like an XY problem to me: Instead of relying on JS to remove the duplicated query parameters, you should look into your server to why it's doing that at the first place. – Terry Dec 22 '20 at 20:50
  • i know but i need that for testing this is a static link with static params through `router navigate` function . – angtesters Dec 22 '20 at 20:54
  • `let url = url.split("&") // returns an array with url parts split at each "&" character.` Then comparing elements in an array is easy... – ISAE Dec 22 '20 at 21:04
  • @ISAE yeah i know that but i need to check how many times then remove repeats or deuplicates params if exists .. will be appreciated if i found help .. thanks . – angtesters Dec 22 '20 at 22:32
  • (https://stackoverflow.com/questions/1960473/get-all-unique-values-in-a-javascript-array-remove-duplicates) – ISAE Dec 22 '20 at 23:14

0 Answers0