在python中,我可以使用元组作为字典的关键。 什么是javascript中的等价物?
>>> d = {} >>> d[(1,2)] = 5 >>> d[(2,1)] = 6 >>> d {(1, 2): 5, (2, 1): 6}对于那些有兴趣的人,我有两个阵列......
positions = ...
normals = ...
我需要制作第三个位置/正常对数组,但不希望有重复对。 我的关联数组将让我检查是否有一个现有的[(posIdx,normalIdx)]对重用或创建一个如果我没有。
我需要一些使用双值键索引的方法。 我可以使用一个字符串,但这似乎比两个数字慢一点。
In python, I can use tuples as the key to a dictionary. What's the equivalent in javascript?
>>> d = {} >>> d[(1,2)] = 5 >>> d[(2,1)] = 6 >>> d {(1, 2): 5, (2, 1): 6}For those who are interested, I have two arrays...
positions = ...
normals = ...
I need to make a third array of position/normal pairs, but don't want to have duplicate pairs. My associative array would let me check to see if I have an existing [(posIdx,normalIdx)] pair to reuse or create one if I don't.
I need some way of indexing using a two-value key. I could just use a string, but that seems a bit slower than two numbers.
最满意答案
Javascript没有元组,但您可以使用数组。
>>> d = {} >>> d[[1,2]] = 5 >>> d[[2,1]] = 6 >>> d Object {1,2: 5, 2,1: 6}Javascript does not have tuples but you can use arrays instead.
>>> d = {} >>> d[[1,2]] = 5 >>> d[[2,1]] = 6 >>> d Object {1,2: 5, 2,1: 6}更多推荐
发布评论