javascript summary function

Posted by Phil Jackson on Stack Overflow See other posts from Stack Overflow or by Phil Jackson
Published on 2010-03-31T05:05:12Z Indexed on 2010/03/31 5:13 UTC
Read the original article Hit count: 576

Filed under:
|
|

Hello, im trying to make a small name summary function depending on the size of the elements container, here's what I have;

function shorten_text(str, size){
    size = size.match( /[0-9]*/ );
    var endValue = Math.floor( Number(size) / 10 );
    var number;
    var newStr;
    for ( number = 0; number <= endValue; number++ ) {
        if( str[number].length != 0 ) {
            newStr += str[number];
        }
    }   
    return newStr + '...';

}
shorten_text('Phil Jackson', '94px');
// output should be 'Phil Jack...'

What I seem to get is undefinedundef... can anyone see where I am going wrong?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about summary