K | Function to find the kth digit from last in an integer n ; If k is less than equal to 0 ; Convert integer into string ; If k is greater than length of the string temp ; Print the k digit from last ; Given Input ; Function call
function kthDigitFromLast ( n , k ) { if ( k <= 0 ) { document . write ( - 1 ) ; return ; } var temp = String ( n ) ; if ( k > temp . length ) { document . write ( - 1 ) ; } else { var req = temp . charAt ( temp . length - k ) document . write ( Number ( req ) ) ; } } var n = 2354 ; var k = 2 ; kthDigitFromLast ( n , k ) ;