How to convert a JavaScript array to C# array?


Let us say our JavaScript array is −

<script>
   var myArr = new Array(5);
   myArr[0] = "Welcome";
   myArr[1] = "to";
   myArr[2] = "the";
   myArr[3] = "Web";
   myArr[4] = "World";
</script>

Now, convert the array into a string using comma as a separator −

document.getElementById('demo1').value = myArr.join(',');

Now, take this to C# −

string[] str = demo.Split(",".ToCharArray());

The above converts the JavaScript array to C#.

Updated on: 22-Jun-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements