How to create a SAFEARRAY in Windows JScript?

ぃ、小莉子 提交于 2019-12-01 07:03:19

Hacky but stripting.dictionary::items is returned as a safe array so in some circumstances (ADSI queries) the following works, however YMMV significantly in trying this with binary data.

function getSafeArray(jsArr) {
    var dict = new ActiveXObject("Scripting.Dictionary");
    for (var i = 0; i < jsArr.length; i++)
    dict.add(i, jsArr[i]);
    return dict.Items();
}

//to a safe array
var safearr = getSafeArray([11,22,33]);

//back to a js array
var jsArr = new VBArray(safearr).toArray();

log(jsArr[2])

JScript doesn't allow you to create safe arrays, you would probably need to write an ActiveXObject to handle this for you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!