You could let .NET handle all the heavy lifting for you with this simple line of code.
This assumes you're using MVC Razor syntax.
var yourJavaScriptArray = @Html.Raw(Json.Encode(Model.YourDotNetArray));
For newer versions of MVC, use:
var yourJavaScriptArray = @Html.Raw(Json.Serialize(Model.YourDotNetArray));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…