ozmike Posted September 25, 2013 Posted September 25, 2013 (edited) Hi What is the syntax to access an javascript array item - from auto IT - using the COM dot syntax? How do you go $js.foo.item(0) when $foo = $js.Eval("var foo = [ 1234, 2345 ] ;") $js = ObjCreate("ScriptControl") $js.language = "Jscript" $js.Eval("var foo = [ 1234, 2345 ] ;") $foo =$js.Eval("foo") Consolewrite("foo.length = " & $foo.length & @CRLF) Consolewrite("foo.item(0) = " & $foo.item(0) & @CRLF) ; FAILS Edited October 14, 2013 by ozmike
Solution ozmike Posted September 30, 2013 Author Solution Posted September 30, 2013 (edited) See my UDF which gives you OO arrays in auto IT using Native windows JSOn . '?do=embed' frameborder='0' data-embedContent>> Or the scripting object Yes you can. 2 ways Just extend the array object type - which javascript allows - the advantage of OO? Add this to your web page Array.prototype.item =function( i ) { return this } ; $js = ObjCreate("ScriptControl") $js.language = "Jscript" $js.Eval("Object.prototype.item =function( i ) { return this[i] } ;"); MAGIC $js.Eval("var foo = [ 1234, 2345 ] ;") $foo =$js.Eval("foo") Consolewrite("foo.length = " & $foo.length & @CRLF) Consolewrite("foo.item(0) = " & $foo.item(0) & @CRLF) ; WORKS Another solution to $obj.item(n) A pure AutoIt solution to get a array object item func OArrayItem ( $o, $i) dim $O_index = 0 for $OO in $o if $i = $O_index then return $OO endif $O_index = $O_index + 1 Next EndFunc $js = ObjCreate("ScriptControl") $js.language = "Jscript" $js.Eval("var foo = [ {""ph"" : 1234}, {""ph"" : 2345 } ] ;") $foo =$js.Eval("foo") Consolewrite("foo.length = " & $foo.length & @CRLF) $oitem = OArrayItem($foo, 0) Consolewrite("$oitem.type " & $oitem.ph & @CRLF) Consolewrite("$oitem.type " & OArrayItem($foo, 0).ph & @CRLF) ; FAILS Edited December 23, 2013 by ozmike
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now