How to convert VBscript array to JavaScript array

2019-06-07 00:45发布

Classic asp:

sub a

aryaa(0,0)=1
aryaa(0,1)=2

end

how to call this array in script function, and how to make this vbscript array to javascript array.

Please help me out from this, since 3 days i m searching for this.

Thanks.

3条回答
霸刀☆藐视天下
2楼-- · 2019-06-07 01:02

In Javascript you don't have a native Matrix object type. But you can use either Object or Array such as:

<script type="text/javascript">
    var aryaa = [ [1, 2] ];
    // aryaa[0][0] = 1
    // aryaa[0][1] = 2
</script>

I hope you find this useful. Check MDN documentation anyway.

查看更多
仙女界的扛把子
3楼-- · 2019-06-07 01:03

Suppose MY VBScript array is aryATTPlans than the below code describe ( VBScript array to Javascript array)

// this is client JS code
var aryATTPlans = new Array();  
var aryATTPlans = new Array(2); 
var i, j;
<%
' this is server VBS code
If IsArray(aryATTPlans) Then
    j=0
    For i = 0 to ubound(aryATTPlans)
        %>
        aryATTPlans[<%= i %>] = new Array(2);
        aryATTPlans[<%= i %>][<%= j %>] = <%= aryATTPlans(i, j) %>;
        <% 
    Next // i
End If 
%> 
查看更多
Rolldiameter
4楼-- · 2019-06-07 01:03

The following function will convert a multi-dimensional VB safe-array into a multi-dimensional JavaScript array.

function VBtoJSArray(vba) {

    var vbarray = new VBArray(vba);

    var d = vbarray.dimensions();

    var dims = [];
    var base = [];
    var params = [];

    for (var i=1; i <= d; i++) {
        dims.push(vbarray.ubound(i)-vbarray.lbound(i) + 1);
        base.push(vbarray.lbound(i));
        params.push(vbarray.lbound(i));
    }

    return convertArray(new Array(dims[0]), 0);

    function convertArray(ax, index) {

        for (var i=0; i < dims[index]; i++) {

            params[index] = i + base[index];

            if (index == dims.length-1) {

                ax[i] = VBArray.prototype.getItem.apply(vbarray, params);
            }
            else {

                ax[i] = new Array(dims[index+1]);
                convertArray(ax[i], index+1);
            }
        }
        return ax;
    }
}
查看更多
登录 后发表回答