Navigate back to the homepage

how to get string after space in javascript?

Infinitbility
JavaScript
August 26th, 2022 · 1 min read
how to get string after space in javascript?

Hi Friends 👋,

Welcome To Infinitbility! ❤️

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

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

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

Today, I’m going to show you How do I get string after space 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 space in javascript?

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

Javascript get string after space example

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

1let string = "infinitbility aguidehub";
2
3let afterLifeStr = string.split(" ").pop();
4
5console.log(afterLifeStr)
6
7// Output
8// 'aguidehub'

Output

Typescript get string after space example

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

1let string: string = "infinitbility aguidehub";
2
3let afterLifeStr: string = string.split(" ").pop();
4
5console.log(afterLifeStr)
6
7// Output
8// 'aguidehub'

Output

React js get string after space example

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

1import React, { useState, useEffect } from "react";
2export default function App() {
3 const [str, setStr] = useState("infinitbility aguidehub");
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 space example

Here, we will take string state with some data and use split() with pop() method to get string after space 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("infinitbility aguidehub");
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 string after colon in javascript?

how to get string after colon in javascript?

An example of get string after colon in javascript with the step-by-step guide.

August 25th, 2022 · 1 min read
how to get string after specific word in javascript?

how to get string after specific word in javascript?

An example of get string after specific word in javascript with the step-by-step guide.

August 24th, 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]