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.

string.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.

let string = "infinitbility aguidehub";

let afterLifeStr = string.split(" ").pop();

console.log(afterLifeStr)

// Output
// '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.

let string: string = "infinitbility aguidehub";

let afterLifeStr: string = string.split(" ").pop();

console.log(afterLifeStr)

// Output
// '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.

import React, { useState, useEffect } from "react";
export default function App() {
  const [str, setStr] = useState("infinitbility aguidehub");

  useEffect(() => {
    let afterLifeStr = str.split(" ").pop();
    console.log(afterLifeStr)
  }, []);

  return (
    <div className="App">
      {str.split(" ").pop()}
    </div>
  );
}

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.

import React, { useState, useEffect } from "react";
import { Text, View } from 'react-native';

export default function App() {
  const [str, setStr] = useState("infinitbility aguidehub");

  useEffect(() => {
    let afterLifeStr = str.split(" ").pop();
    console.log(afterLifeStr)
  }, []);

  return (
    <View>
      <Text>{str.split(" ").pop()}</Text>
    </View>
  );
}

Output

I hope it helps you, All the best đź‘Ť.