Take a look at this example:
  var c=document.getElementById("myCanvas");
   var ctx=c.getContext("2d");
    // First rectangle created    
    ctx.fillRect(20,20,150,100);
    // Second rectangle created    
    ctx.fillRect(20,150,150,100);
    // Third rectangle created    
    ctx.fillRect(20,300,150,100);
I created three rectangles here. After creating third rectangle I want to rotate first rectangle. How do i get reference of first rectangle now?
 
     
     
     
     
    