3 ms·
Did this example confuse anyone else? > For instance, given an Array in JavaScript, > window.x = ["a", "b", "c"]; > We can access it in Python as, ''' >>>
by neoncontrails 5y ago
Did this example confuse anyone else?
> For instance, given an Array in JavaScript,
> window.x = ["a", "b", "c"];
> We can access it in Python as,
'''
>>> from js import x # import x from global Javascript scope
>>> type(x)
<class 'JsProxy'>
>>> x[0] # can index x directly
'a'
>>> x[1] = 'c' # modify x
>>> x.to_py() # convert x to a Python list
['a', 'c']
'''
Should be ['a', 'c', 'c'], shouldn't it? Is this a typo? Implicit cast to set somewhere?
- rthz 5y agoYes, it was indeed a typo. Thanks!