Hi Friends 👋,
Welcome To Infinitbility! ❤️
To get string after dot in javascript, use split()
method with pop()
method it will return those string which after then your dot or which you used to split the string.
Let’s see short example to use split()
method with pop()
method to get string after dot.
string.split(".").pop();
Today, I’m going to show you How do I get string after dot 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 dot in javascript?
Here, I will show get string after dot examples in javascript, typescript, react js and react native.
Javascript get string after dot example
Here, we will take string variable with some data and use split()
with pop()
method to get string after dot in javascript.
let string = "file/newuser.jpg";
let afterLifeStr = string.split(".").pop();
console.log(afterLifeStr)
// Output
// 'jpg'
Output
Typescript get string after dot example
Here, we will take string variable with some data and use split()
with pop()
method to get string after dot in typescript.
let string: string = "file/newuser.jpg";
let afterLifeStr: string = string.split(".").pop();
console.log(afterLifeStr)
// Output
// 'jpg'
Output
React js get string after dot example
Here, we will take string state with some data and use split()
with pop()
method to get string after dot in react js.
import React, { useState, useEffect } from "react";
export default function App() {
const [str, setStr] = useState("file/newuser.jpg");
useEffect(() => {
let afterLifeStr = str.split(".").pop();
console.log(afterLifeStr)
}, []);
return (
<div className="App">
{str.split(".").pop()}
</div>
);
}
Output
React native get string after dot example
Here, we will take string state with some data and use split()
with pop()
method to get string after dot in react native.
import React, { useState, useEffect } from "react";
import { Text, View } from 'react-native';
export default function App() {
const [str, setStr] = useState("file/newuser.jpg");
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 👍.