I have encountered a challenge with my coding project - I have an array of objects created using Javascript, and now I need to access and manipulate it using VBScript. Unfortunately, I am struggling to figure out how to properly loop through the array in my VBScript code using the myArray
object.
This example provided is a simplified version of my issue at hand. I am unable to switch the default language of the page. The creation of the myArray
object must remain in javascript. Additionally, I have to display the array utilizing 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
%>