2

I have found that encodeURIComponent works in most cases but when I pass an array, it doesn't work as expected. Here is my code:

var orderArray = [223746903996283,223525203804543]
var orders = encodeURIComponent(orderArray);
Logger.log(orders);

orders value is 223746903996283%2C223525203804543.

The expected value is %5B223746903996283%2C223525203804543%5D.

Thank you so much in advance.

Sample output on an online encoder

1
  • You are trying to encode the string not the array. Commented Mar 15, 2019 at 0:28

1 Answer 1

6

Convert it to a string first using JSON.stringify:

var orderArray = [223746903996283,223525203804543]
var orders = encodeURIComponent(JSON.stringify(orderArray));
console.log(orders);

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

Comments

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.