How to convert a JavaScript array to C# array?

CsharpProgrammingServer Side Programming

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#.

raja
Published on 31-Aug-2018 15:12:53
Advertisements