This is my Temp url and I'm trying to get image name
var str='C:\fakepath\alfa_company.png';
my expected out put like this:
var url='alfa_company.png';
This is my Temp url and I'm trying to get image name
var str='C:\fakepath\alfa_company.png';
my expected out put like this:
var url='alfa_company.png';
In Javascript "\" has a special meaning. So, it doesn't get included in your resultant string.
Try
let u = String.raw`C:\fakepath\alfa_company.png`;
u.split("\\")[u.split("\\").length-1]
or
let u = String.raw`C:\fakepath\alfa_company.png`;
u.split("\\").pop()
to understand it better go through How can I use backslashes (\) in a string?
You don't need any jQuery for that :)
const path = 'C:\\fakepath\\alfa_company.png';
const filename = path.split('\\').pop(); // alfa_company.png
You need to use double backlashes because JavaScript treats them as escape characters.