JSFiddle - React, Tailwind, and code Playground

JavaScript

var str = "https://example.com/image.jpg";
var dotIndex = str.lastIndexOf('.');
var ext = str.substring(dotIndex);
alert(ext);