W
W
WhiteBachelor2018-11-12 13:27:20
JavaScript
WhiteBachelor, 2018-11-12 13:27:20

How to pass multiple parameters to split() to split?

You need to make a function that translates the received string into camel-case. That is, so that "bgColor" is obtained from "bg-color". I did like this:

function toCamelCase(str){
  return str.split(' ' || '-' || '_').reduce((sum, cur) =>
  {return sum + cur.charAt(0).toUpperCase + cur.substr(1)})
}

This function only works if the words are separated by spaces. I also checked with &&: it doesn't work either. How can you do that. so that split() splits according to all the necessary parameters?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AlexKeller, 2018-11-12
@WhiteBachelor

str.split(/[ _-]/g);
The separator parameter can be either a string or a regular expression
Plus you need to add parentheses to call toUpperCase()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question