Navigate back to the homepage

how to get string after specific character in javascript?

Infinitbility
JavaScript
August 23rd, 2022 · 1 min read
how to get string after specific character in javascript?

Hi Friends 👋,

Welcome To Infinitbility! ❤️

To get string after specific character in javascript, use split() method with pop() method it will return those string which after then your specific character or which you used to split the string.

Let’s see short example to use split() method with pop() method to get string after specific character.

1string.split("-").pop();

Today, I’m going to show you How do I get string after specific character in javascript, as above mentioned, I’m going to use the above-mentioned split() method with pop() method.

Let’s start today’s tutorial how do you get string after specific character in javascript?

Here, I will show get string after specific character examples in javascript, typescript, react js and react native.

Javascript get string after specific character example

Here, we will take string variable with some data and use split() with pop() method to get string after specific character in javascript.

1let string = "[email protected]";
2
3let afterLifeStr = string.split("@").pop();
4
5console.log(afterLifeStr)
6
7// Output
8// '2022'

Output

Typescript get string after specific character example

Here, we will take string variable with some data and use split() with pop() method to get string after specific character in typescript.

1let string: string = "[email protected]";
2
3let afterLifeStr: string = string.split("@").pop();
4
5console.log(afterLifeStr)
6
7// Output
8// '2022'

Output

React js get string after specific character example

Here, we will take string state with some data and use split() with pop() method to get string after specific character in react js.

1import React, { useState, useEffect } from "react";
2export default function App() {
3 const [str, setStr] = useState("[email protected]");
4
5 useEffect(() => {
6 let afterLifeStr = str.split("@").pop();
7 console.log(afterLifeStr)
8 }, []);
9
10 return (
11 <div className="App">
12 {str.split("@").pop()}
13 </div>
14 );
15}

Output

React native get string after specific character example

Here, we will take string state with some data and use split() with pop() method to get string after specific character in react native.

1import React, { useState, useEffect } from "react";
2import { Text, View } from 'react-native';
3
4export default function App() {
5 const [str, setStr] = useState("[email protected]");
6
7 useEffect(() => {
8 let afterLifeStr = str.split("@").pop();
9 console.log(afterLifeStr)
10 }, []);
11
12 return (
13 <View>
14 <Text>{str.split("@").pop()}</Text>
15 </View>
16 );
17}

Output

I hope it helps you, All the best 👍.

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

how to get last word of string in react js?

how to get last word of string in react js?

An example of get last word of string in react js with the step-by-step guide.

August 22nd, 2022 · 1 min read
how to get last word of string in react native?

how to get last word of string in react native?

An example of get last word of string in react native with the step-by-step guide.

August 22nd, 2022 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]