Remove part of the string

3

I need to modify a string with jQuery. Suppose I have a variable address:

var endereço = "Rua emanuel meira martins 85 cic curitiba...";

The idea is to remove all letters after position 15 and add three dots (...).

How can I perform this operation?

    
asked by anonymous 15.10.2014 / 19:48

1 answer

5

You can do this:

var endereço = 'Rua emanuel meira martins 85 cic curitiba'.slice(0, 15) + '...';

In this case you give: Rua emanuel mei...

The native method .slice () accepts two parameters, the starting point and the end point of the portion of the original that is to be used. This is pure JavaScript. You do not need jQuery here.

    
15.10.2014 / 19:49