This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.
The length protoype property of the Table object returns the length of the table, i.e. the number of references stored in the table.
var tableLength = table.length;
A number.
The following example (see table.html on GitHub, and view it live also) compiles and instantiates the loaded table.wasm byte code using the WebAssembly.instantiate() method. It then exports a table from the module and retrieves the references stored in it.
fetch('table.wasm').then(function(response) {
response.arrayBuffer().then(function(bytes) {
WebAssembly.instantiate(bytes).then(function(obj) {
var tbl = obj.instance.exports.tbl;
console.log(tbl.get(0)()); // 13
console.log(tbl.get(1)()); // 42
console.log(tbl.length);
});
});
}); Note how you've got to include a second function invocation operator at the end of the accessor to actually retrieve the value stored inside the reference (e.g. get(0)() rather than get(0)) — it is a function rather than a simple value.
At the end of the inner block we log the length of the table instance to the console.
| Specification | Status | Comment |
|---|---|---|
| Web Assembly JavaScript API The definition of 'length' in that specification. | Draft | Initial draft definition. |
| Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
|---|---|---|---|---|---|---|
| Basic support | No support[1] | No support | No support[2] | No support | No support[1] | No support |
| Feature | Android | Android Webview | Edge | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile | Chrome for Android |
|---|---|---|---|---|---|---|---|---|
| Basic support | No support | No support[1] | No support | No support[2] | No support | No support | No support | No support[1] |
[1] Experimental support can be enabled in Chrome 51+ and Opera 38+ by going to chrome://flags and enabling the Experimental WebAssembly flag.
[2] Experimental support can be enabled in Firefox 47+ by enabling the javascript.options.wasm flag in about:config.
© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/length