how would I convert this c# code to javascript to accomplish the same thing.
var s = styles.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
If styles
is a string, it's as simple as:
styles.split(/[\r|\r\n]/);
var styles = 'body {font-size: 12px;}\n\ .someClass {color: red}'; document.querySelector('#result').textContent = '[' + (styles.split(/[\r|\r\n]/)) +']';
<pre id="result"></pre>
split
is an Array
. You can't split an Array
, you can split a String. I can't say much on your usage of the splitted String style
, but it seems wrong to use an Array
as selector within a query. You can use elements from an Array
though: s[element.position]
, e.g. s[0]
returns the first element of array s
.