I am using the function to set the https to the url passed in input.
setHttps(a) {
if (a.indexOf('http://') > 0){
a.replace('http', 'https')
console.log('priting url if...... ', a);
} else if(a.indexOf('https://') == -1 && a.indexOf('http://') == -1) {
a = a.replace (/^/,'https://');
console.log("printing url else........ ", a);
}
return a;
}
When I pass the following:
- www.example.com --> converts to ---> https://www.example.com
- http://www.example.com --> doesn't get converted to ---> https://www.example.com
Why? It looks like indexOf('http://') is unable to find http:// in the string.
a.indexOf('http://') > -1