Insha Profile picture
15 Oct, 18 tweets, 5 min read
Top 13 JavaScript String methods every JS beginner should know!!

A Thread 👇
A quick recap of JavaScript Strings:

Strings are used for storing and manipulating text in JavaScript.
Strings can be enclosed within either single quotes, double quotes, or backticks.

Here's a simple demonstration of creating Strings.
Some of the commonly used JavaScript String methods:

string.length
charAt(index)
concat()
replace()
split()
slice(start, end)
substring(start,end)
substr(start, length)
toLowerCase()
toUpperCase()
includes()
trim()
padStart() and padEnd()
1️⃣ String Length

The length property is a read-only property that returns the length of a string.
There will be no effect if we try to change it manually.
2️⃣ charAt(index)

This method provides the char value present at the specified index.

The charAt() method takes in the index as a parameter - An integer between 0 and "str.length - 1" and returns the char value at the specified index.
3️⃣concat()

The concat() method concatenates two or more strings and returns a new string containing the combined text of the strings provided.
If the arguments are not of the type string, they are converted to string values before concatenating.
4️⃣ replace()

The JavaScript string replace() method is used to replace a part of a given string with a new substring.

Note: The replace() method does not change the string it is called on. It simply returns a new string.
5️⃣ split()

This string method splits a string into a substring array, then returns that newly created array.

It takes in 2 parameters - pattern describing where each split should occur and the separator can be a simple string or it can be a regular expression.
6️⃣ slice(start, end)

The slice() method extracts and returns a part of the string from start to (excluding) the end.

If there's no second argument specified, then splice method goes till the end of the string.

Negative values from start/end is also possible.
7️⃣ substring(start,end)

This method is almost similar to slice().

The substring() method returns the part of a string between start and end.

It takes in 2 parameters: starting index and the ending index. Negative arguments are not supported, they're r=treated as 0.
8️⃣ substr(start, length)

This method takes in two parameters: first one is the starting index and the second parameter specifies the length of the extracted part.
9️⃣ toLowerCase()

The toLowerCase() method returns the string converted to lowercase.
🔟 toUpperCase()

The toUpperCase() method returns the string converted to uppercase.
1️⃣1️⃣ includes()

The includes() method performs a search to determine whether one string may be found within another string, returning true or false as appropriate.
1️⃣2️⃣ trim()

The trim() method removes whitespace from both sides of a string.
1️⃣3️⃣ String Padding- padStart() and padEnd()

The padStart() and padEnd() methods support padding at the beginning and at the end of a string.

It takes in the two-parameter:
1- targetLength: length of the final string
2- padString: The string to pad the current string with.
All string methods return a new string. They don't modify the original string.
In other words, Strings are immutable.
That's all for this thread!

In JavaScript, strings are of great importance and are most commonly used.
A string can represent an object as well as the primitive data type.

If you learned something new from this thread make sure to retweet it. 🔥😊

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Insha

Insha Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @Insharamin

5 Oct
Are you a Front-end Developer?

If yes, these amazing websites are a goldmine for you!

A Thread 👇
1️⃣ Responsively

A must-have DevTool for all Front-End developers that will make your job easier.
Develop responsive web apps 5x faster with this open-source tool!

📎responsively.app
2️⃣ Small Dev tools

FREE tools for developers like encoder/decoder, HTML/CSS/Javascript formatters, minifiers, fake or test data generators & much more.

📎smalldev.tools
Read 12 tweets
30 Sep
With the evergrowing demand for Technical writing.

You can earn 1000$/ week. 💰📝

Let's know-how? 👇
⚡What is Technical Writing?

Technical writing is a writing discipline where you get to explain a particular topic to the audience in the easiest way possible!

If you've got a deep knowledge of something and want to amplify your voice- Technical writing is the way to go!
⚡There are a number of platforms that pay you well for writing 💰

Some of them are:

1- sitepoint.com
2- digitalocean.com
3- css-tricks.com
4- auth0.com
5- hasura.io
6- contentlab.io

And many more!
Read 9 tweets
28 Sep
Hey there JavaScript Developers 👋

Let's deep dive into the concept of Optional Chaining in JavaScipt.

With optional chaining, we can check to see if something exists and handle an error gracefully.

A Thread 👇
What the heck is Optional chaining? 🥴

The optional chaining " ?." is a recent addition to the language which is a secure way to access nested object properties, even if an intermediate property doesn’t exist.
Optional chaining in JavaScript is very useful - we can access values without checking if the parent object exists. Instead of returning an error, it will return null or undefined.
Read 19 tweets
18 Sep
8 Crazy Underrated Websites for Designers that you should know.

A Thread 👇
1️⃣ Wordmark

Wordmark helps you choose fonts by quickly displaying your text with your fonts.

📎 wordmark.it
2️⃣ Figside

Ship Websites with Figma.
Figside is perfect for personal websites, portfolio, landing pages and more.

📎 figside.com
Read 10 tweets
14 Sep
6 Underrated Websites that you should know.

A Thread 👇
1️⃣ Gifrun

With this tool, you can convert any video into a GIF format.

📎 gifrun.com
2️⃣ Uberduck

Uberduck.AI is a tool that allows you to make any text sound like it's been read by a celebrity or fictional character, and the results are incredible.

📎 uberduck.ai/#mode=tts-basic
Read 8 tweets
7 Sep
Do you use Tailwind CSS?

Know these 5 websites to get Tailwind components pre-made🔥😎
1️⃣ Tailwind Components

A free repository for community components using TailwindCSS.
You can find Tailwind charts, grids, inputs, forms, templates, and much more.

📎tailwindcomponents.com
2️⃣ Tailblocks

Tailblocks shares handpicked Tailwind blocks, Tailwind templates, Tailwind Components, and other free resources related to Tailwind CSS.

📎tailblocks.cc
Read 7 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(