I want to Update rel=canonical href using Java Script

Here ya go @KranthiKiranGude, this is how you could change the href attribute in javascript. First you select the DOM element, then you change the attribute.

<script>
var uC = document.querySelectorAll("link[rel='canonical']")[0];
var newURL = "https://my.coolforum.com/newlink";
uC.setAttribute("href", newURL);
</script>

Of course, you will need some logic based on the page you want operate on.

Generic example logic:

<script>
if("the_actual_page_url_or_id" == "my_interesting_page_url_or_id")
{
   var uC = document.querySelectorAll("link[rel='canonical']")[0];
   var newURL = "https://my.coolforum.com/newlink";
   uC.setAttribute("href", newURL);
}
</script>

Hope this helps.