shanky singh
shanky singh

Reputation: 1141

How to make array to comma seperated correctly

I have an array like arr = ["1000","2000"].

I am converting this into comma separated value and then adding to my url.

Here I am converting to comma separated.

arr = arr.toLocaleString();

In my url, In chrome it is coming correctly but in IE it is coming % before value.

Chrome : /1001,2000/
    IE : /1001,%2000/

Url in IE is wrong. Anybody help me how to fix this.

Extra percentage is coming in url while checking in iE.

Upvotes: 2

Views: 269

Answers (1)

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100205

use .join() to join all elements of array into string ,and encode it, like:

var arr = ["1000","2000"],
    str = arr.join(","),
    encodedStr = encodeURIComponent(str); // "1000%2C2000"

Upvotes: 3

Related Questions