JSFiddle - React, Tailwind, and code Playground

by pratik24

JavaScript

var str = "a b c d e f";

var lastIndex = str.lastIndexOf(" ");

console.log(str.slice(0, lastIndex);
            
console.log(str.lastIndexOf(" "));