Javascript array to VBScript

I have an array of objects built using Javascript and I need to read it using VBScript (as in the example below). I cannot find a way to loop through the array in my VbScript code as the myArray object.

The example is a simplification of my problem. I cannot change the default language of the page. The myArray object must be built using javascript. The array must be output using inline vbscript.

<%@ Language="VBScript" %>

<script language="javascript" runat="server">

    var myArray = [
        {
            name: "object 1"
        },
        {
            name: "object 2"
        },
        {
            name: "object 3"
        }
    ];

</script>

<%
    Response.Write(myArray) ' [object Object],[object Object],[object Object]
    'Response.Write(myArray(0)) ' ERROR
    'Response.Write(myArray[0]) ' ERROR
    Response.Write(myArray.[0]) ' [object Object]
    Response.Write(myArray.[0].name) ' object 1
    Response.Write(VarType(myArray)) ' 8
    Response.Write(myArray.length) ' 3
    Response.Write(VarType(myArray.[0])) ' 8
    Response.Write(VarType(myArray.[0].name)) ' 8
    Response.Write(TypeName(myArray)) ' JScriptTypeInfo
    Response.Write(TypeName(myArray.[0])) ' JScriptTypeInfo

    ' ERROR
    ' Type mismatch: 'UBound'
    'Response.Write(UBound(myArray))

    ' ERROR
    ' Object doesn't support this property or method: 'myArray.i'
    'Dim i
    'For i = 0 To myArray.length - 1
    '    Response.Write(myArray.[i])
    'Next
%>

Answers


It seems the JScript array methods are still available via VBScript:

<script language="javascript" runat="server">
    var myArray = [
        {
            name: "object 1"
        },
        {
            name: "object 2"
        },
        {
            name: "object 3"
        }
    ];
</script>

<%
    Do While myArray.length > 0
        response.write myArray.shift().name
        response.write "<br>"
    Loop
%>

Need Your Help

AFNetworking POST get 403 forbidden, but Curl works

afnetworking

I want to use AFNetworking to POST to sinatra project to get json data. AFNetwroking always get back 403 status code. But curl works as expect. Why?