skip to Main Content
    const { selectedButton } = this.state;

    var boundingBoxCollection = [];
    console.log(boundingBoxCollection.length);

    var boundingBoxes = document.querySelectorAll('.cropper-face');
    console.log("I am ice"+boundingBoxes.length);

    if(boundingBoxes.length > 0){
      boundingBoxes.forEach(elem => {
        if(!boundingBoxCollection.includes(elem)){
          boundingBoxCollection.push(elem);
        }
      });
    }

my boundingBoxCollection is not updated

fix this, I want my array to be updated

2

Answers


  1. Chosen as BEST ANSWER
    const { selectedButton } = this.state;
    
    // Ensure boundingBoxCollection is initialized properly
    var boundingBoxCollection = Array.from(document.querySelectorAll('.cropper-face'));
    
    console.log("Initial length: " + boundingBoxCollection.length);
    
    // Loop through the selected elements and push them into boundingBoxCollection
    var boundingBoxes = document.querySelectorAll('.cropper-face');
    console.log("I am ice" + boundingBoxes.length);
    
    if (boundingBoxes.length > 0) {
      boundingBoxes.forEach(elem => {
        if (!boundingBoxCollection.includes(elem)) {
          boundingBoxCollection.push(elem);
        }
      });
    }
    

  2. const { selectedButton } = this.state;
    
    // Ensure boundingBoxCollection is initialized properly
    var boundingBoxCollection = Array.from(document.querySelectorAll('.cropper-face'));
    
    console.log("Initial length: " + boundingBoxCollection.length);
    
    // Loop through the selected elements and push them into boundingBoxCollection
    var boundingBoxes = document.querySelectorAll('.cropper-face');
    console.log("I am ice" + boundingBoxes.length);
    
    if (boundingBoxes.length > 0) {
      boundingBoxes.forEach(elem => {
        if (!boundingBoxCollection.includes(elem)) {
          boundingBoxCollection.push(elem);
        }
      });
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search