Роман Андреевич,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
span{
height: 50px;
width: 50px;
background-color: #EEE8AA;
display: inline-block;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(function() {
var a = [
[]
];
$("body").on("click", "span", function() {
var b = $(this).data("num"),
c = a[a.length - 1];
3 == c.length ? a.push([b]) : c.push(b);
$(".out").text(JSON.stringify(a, null, 4))
})
});
</script>
</head>
<body>
<span data-num="0">0</span>
<span data-num="1">1</span>
<span data-num="2">2</span>
<span data-num="3">3</span>
<span data-num="4">4</span>
<span data-num="5">5</span>
<span data-num="6">6</span>
<span data-num="7">7</span>
<span data-num="8">8</span>
<span data-num="9">9</span>
<div class="out"></div> </body>
</html>