let imageSRC = "Enter Full URL Here";
let firstCut = imageSRC.substr(0, imageSRC.lastIndexOf('/'));
let secondCut = firstCut.substr(0, firstCut.lastIndexOf('/'));
console.log(secondCut);
The code above worked great for me to replace the “&” character with the word “and” in my page element variables. I probably didn’t make the code very efficient, but it works great.
let tempCompany = $w( ‘#companyname’ ).value; var newCompany = tempCompany.replace(/&/ g , ‘and’ );
$w( ‘#companyname’ ).value = String(newCompany);
FYI, I needed to replace the & character because the SendGrid email system was cutting off the body of the email message as soon as there was an &.
Although this is an old post, thanks for sharing. Code looks efficient enough to me.
Interesting about SendGrid cutting of the body of the email message. I’m not sure of the format of that field, but you might be able to use the & by using an escape character or an HTML entity.