Whilst looping through all layers in a document is on SO, it can be confusing from looping over a number of layers to the awkwardness of looping over a psd with groups in it.
Basically, you need a recursive function to loop over the groups.
Point of note, make sure to switch off any dialog boxes at the start of the script when changing text. Otherwise you have to validate every text change confirmation.
// Switch off any dialog boxes
displayDialogs = DialogModes.NO; // OFF
var itemsAry=['emil','lardtub','100','jsbus', 'rasmus','null','1000000'];
// group layer vegetables
var theLayers = collectAllLayers(app.activeDocument, 0);
// function collect all layers
function collectAllLayers (theParent, level)
{
for (var m = theParent.layers.length - 1; m >= 0; m--)
{
var theLayer = theParent.layers[m];
// apply the function to layersets;
if (theLayer.typename == "ArtLayer")
{
if (theLayer.kind == "LayerKind.TEXT")
{
theLayer.textItem.contents=itemsAry[m];
}
}
else
{
collectAllLayers(theLayer, level + 1)
}
}
}
// Make sure dialogs back on
displayDialogs = DialogModes.ALL; // ON
app.activeDocument.layerSets