text = '123456789'; end = 4; leng = 3; alert(text.substr(end, leng)); alert(text.substr(end-leng+1, leng))