1

With Pandas, say I wanted to multiply each number in a dataframe series by 2, I could write something like

f = lambda x: x*2
df.col.apply(f)

With Node, say I want to encode each url in an array. Is there a similar function. I'm wondering if the following will work:

array.map(encodeURIComponent)

Or, do I need to do the following:

const encodeUrls = (url)=>{return encodeURIComponent(url)}
cs95
  • 330,695
  • 80
  • 606
  • 657
Yale Newman
  • 1,031
  • 10
  • 22

1 Answers1

2

map will do the work.

const urls = ['https://w3schools.com/my test.asp?name=ståle&car=saab', 'http://www.example.org/a file with spaces.html'];

console.log(urls.map(encodeURI))

You can read about the difference between encodeURI and encodeURIComponent here https://stackoverflow.com/a/3608791/4796844

radzak
  • 2,656
  • 1
  • 16
  • 24