Remove part of the string

Posted on

Question :

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?

    

Answer :

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.

    

Leave a Reply

Your email address will not be published. Required fields are marked *