attrlist – a flat [[mdn>Web/JavaScript/Reference/Global_Objects/Object|Object]], containing a name-value pair of attributes to add to the ''
'' element (optional).
Returns:
A new [[mdn>Web/HTML/Element/table|table]] element with sub-element representing the content of the array.
Notes:
* The returned element structure does not have any style information. It is up to the page to provide styling for the table. Please see [[framework:page:p-console:index|$p.console]] for an example how the table can be styled.
* The array values will be serialized using the [[mdn>Web/JavaScript/Reference/Global_Objects/JSON/stringify|JSON.stringify()]] method. Please see this function for limitations of this approach.
* The method uses [[mdn>Web/API/Node/textContent|.textContent]] to insert the values to the structure, which makes it safe to use HTML special characters such as ''<'', ''>'' or ''&'' in the array content.
===== Example =====
Given an array that is defined as follows:
const myArr = ["first", 2, 3.1, "fourth", "fifth", "sixt", [1,2,3,4,5,6,7], "eigth", {"name": "nineth"}, "tenth"];
The function creates a HTML structure as this:
#
Value
0
"first"
1
2
2
3.1
3
"fourth"
4
"fifth"
5
"sixt"
6
[1,2,3,4,5,6,7]
7
"eigth"
8
{"name":"nineth"}
9
"tenth"
which could render (with additional CSS) as follows:
{{:toolbox:arrays:tohtml:array-tohtml-example.png?nolink|jMini Array toHtml example screenshot}}
An example of an array table with different value types (see [[framework:page:p-console:index|$p.console]] for more information).
===== See also =====
* [[framework:page:p-console:index|$p.console]]