Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8386833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:03:05+00:00 2026-06-09T18:03:05+00:00

I have to delete a shape in canvas. The following code was written- function

  • 0

I have to delete a shape in canvas.

The following code was written-

  function deleteCircle(circle, propName) {
      for( i = 0; i < circle.length; i++) {
        circle[i].erase();      
      }
    }
   circle.prototype.erase=function() {
      delete this;
    }

when i am running this code at i=0 it is going to the erase function.
but after the frst delete it is not coming back to deletecircle.
This is just a rough code… i m just coonfused that after delete this…. that is after the object is deleted doest the code come back to deletecircle ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:03:07+00:00Added an answer on June 9, 2026 at 6:03 pm

    As other users have said, modifying size of your array during the loop is a bad idea.
    Try:

    var circle = new Array();
    circle[0]=1;
    circle[1]=2;
    circle[2]=3;
    circle[3]=4;
    
    function deleteCircle(circle, propName) {
        while(circle.length!==0){
            erase(circle.pop());
        }
    }
    function erase(elem){
        delete elem;
    }
    
    alert(circle.length);
    deleteCircle(circle,null);
    alert(circle.length);
    

    LIVE DEMO

    EDIT: Sorry didn’t notice you changed the code. Updated:

    function circle(){};
    circle.prototype.erase = function(){
        delete this;
    }
    
    var circles = [new circle, new circle, new circle];
    
    function deleteCircle(circle, propName) {
        while(circle.length!==0){
            circle.pop().erase();
        }
    }
    
    function circle(){}; //or however you define your class
    circle.prototype.erase = function(){ //extend the class
        delete this;
    }
    
    var circles = [new circle, new circle, new circle]; //your array
    
    function deleteCircle(circle, propName) {
        while(circle.length!==0){
            circle.pop().erase();
        }
    }
    
    alert(circles.length);
    deleteCircle(circles,null);
    alert(circles.length);
    

    LIVE DEMO

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem trying to delete an entire row using the code as
I have a delete issue at the moment. We do not have permission to
I have a delete button on a table and a jquery on click eventlistener
I have to delete some elements of my array, but without rearrange array. If
I have a delete form wherein the user will enter the pnum to be
I have to delete all rows of a model with condition fkey_id = 1
I have a delete button on my web site which I want to add
I have a delete button and on clicking cancel on the confirm box, it
I have to delete folder with more than 30000 images. I have '.nomedia' file
I want to have a delete user link in a normal Activerecord table, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.