Did you all test your solutions in a Real World Scenario?
Theoretically it should work this way (if we neglect that a layer could be invisible, too), but even without the problem of invisible layers app.pasteInPlace() prefers to paste into the original layer, if the option "Paste Remembers Layers" is checked.
So I would recommend to do the following:
var oldPasteRem = app.clipboardPreferences.pasteRemembersLayers;//uncheck "Paste Remembers Layers"
app.clipboardPreferences.pasteRemembersLayers = false; for (i = 0; i < app.activeDocument.layers.length; i++) { //Maybe the user does not want objects pasted to invisible layers: if(app.activeDocument.layers[i].visible == true&& app.activeDocument.layers[i].locked == false) { app.activeDocument.activeLayer = app.activeDocument.layers[i]; app.pasteInPlace(); };};//Restore the old condition:
app.clipboardPreferences.pasteRemembersLayers = oldPasteRem;
Uwe