var text = '12345'; var i = text.length; var len = i - 1; var line = text; while( i-- ) { line = line.slice( -1 ) + line.slice( 0, len ); alert( line ) ; }