Trimming and Padding Strings

Video

JavaScript Notes

JavaScript
    // Trimming and Padding Strings
    // trim( ), trimLeft( ), trimright( )
    // padStart(minLength [, padString]), padEnd( )
    
    let name = 'Sterling';
    let longname = '	Archer	';
    let log = console.log;
    
    log( longname.trim( ) );	        // returns ‘Archer’ – as a new string 
    log( longname.trimLeft( ), 'x');	// returns ‘Archer	‘ ‘x’
    
    log( name.padStart(10));	        // puts spaces in beginning to ensure string is 10 characters long 
    log( name.padEnd(10));	            // puts spaces at the end to ensure string is 10 characters long 
    log( name.padStart(10, 'asdahad') )	// returns ‘asSterling’