# Re: build 3x3 table from one array

**URL:** <https://www.ruby-forum.com/t/re-build-3x3-table-from-one-array/82698>\
**Category:** Ruby\
**Created:** [March 16, 2006, 7:29pm UTC](https://www.ruby-forum.com/t/re-build-3x3-table-from-one-array/82698 "2006-03-16T19:29:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [March 16, 2006, 7:29pm UTC](https://www.ruby-forum.com/t/re-build-3x3-table-from-one-array/82698/1 "2006-03-16T19:29:26Z")

</div>

> I think they are really cool.
> 
> I am stuck trying to figure out how to take an array of data and  
> dynamically build a 3x3 html table from it without standard for loops.

If you don’t mind a 3rd party solution:

require ‘html/table’  
include HTML

array = [1,2,3,4,5,6,7,8,9]

table = Table.new  
table.push(Table::Row.new(array[0…2]))  
table.push(Table::Row.new(array[3…5]))  
table.push(Table::Row.new(array[6…9]))

puts table.html

| 1 | 2 | 3 |
| 4 | 5 | 6 |
| 7 | 8 | 9 |
