3

I've got a complex data structure in JavaScript composed out of numbers and containers (arrays in this case). What would be the fastest and/or most memory efficient way to store and process this? Is there something non-obvious, better speed and/or memory-wise, than for example [ [ 1, 2], [3, 4] ] which requires something similar to typeof to distinguish between tree branches and leaves when scanning it? The structure is very large with about a million numbers.

I've set up a jsperf test to evaluate some methods of distinguishing between numbers and objects, and typeof seems fastest except in Opera and IE:

http://jsperf.com/typeof-number-vs-object

4

1 に答える 1

1

試す:

isNaN(myVar)

trueidmyVarが数値でない 場合は false を返します。

ドキュメント

どうやら、この機能は完全にバグがないわけではありません... (私がリンクしたドキュメントを参照してください)

于 2013-02-15T10:39:09.963 に答える