Remove part of the string

Asked

Viewed 836 times

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 points (...).

How can I perform this operation?

1 answer

5

You can do it like this:

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

Which in this case gives: Rua emanuel mei...

The native method .Slice() accepts two parameters, the starting point and the end point of the original that will be used. This is pure Javascript. No need for jQuery here.

  • 1

    thanks !________

  • 1

    @user14579 if the answer solved your problem you can mark as accepted. I noticed that you have other questions where you can ask the same.

  • @Zuul no problem. Fixed too :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.