My personal CRUD project -issues with Read after class Delete(d)

Hallo. After a class is deleted (it’s stored in an object that’s been push into an array, which I dubbed n), the find code is not working. It reads on the console:

Uncaught TypeError: (destructured parameter) is undefined
 foundIdade file:///Users/myname/Desktop/practice BC/cadastro/js/cadastro-6.js:63
 find file:///Users/myname/Desktop/practice BC/cadastro/js/cadastro-6.js:63
 onclick file:///Users/myname/Desktop/practice BC/cadastro/cadastro-6.html:1

I’ve been trying to solve this issue for some time but to no avail. I tried to decrease the classes’ keys (if the #2 is erased, you get 0, 1, 3 ), but it didn’t work. Here’s my code:

let find2;
function find() {
    find2 = document.getElementById('find');        
    let foundNome = n.find(({name}) => name === find2.value);
    let foundIdade = n.find(({age}) => age === find2.value);
    let foundEmail = n.find(({email}) => email === find2.value);
    let foundId = n.find(({id}) => Number(id) === Number(find2.value)); 
    
    if(typeof foundAge !== 'undefined' && typeof foundName !== 'undefined' && typeof foundId !== 'undefined') {

        if(foundName.name !== find2.value) {
        } 
        if(foundAge.age === find2.value) {
            
        };
        if(foundEmail.email === find2.value) {
            
        };
        if(Number(foundId.id) === Number(find2.value)) {
            
        };
    };
    console.log(foundName);
    console.log(foundAge);
    console.log(foundEmail);
    console.log(foundId);
    document.getElementById('find').value = '';
    
};

let deleteInfo;
function deleteContent() {
    deleteInfo = document.getElementById('delete');
    delete n[clockContainer.get(deleteInfo.value)];
    delete containerDataStudents[clockContainer.get(deleteInfo.value)];  
    document.getElementById('delete').value = '';
};

Thanks and I appreciate the help.

I’m not familiar with the delete, but from what I read it deletes class properties, not whole classes or array elements… is that correct?

It deletes the whole class:

By the way: nome = name and idade = age

Did you ever resolve your issue? If not, can you give a link to your full code (maybe on GitHub or Codepen), so we can take a look at how the overall app works?

Hi Randell. No, I haven’t.

Here’s the GitHub link: GitHub - 2bXorNot/CRUD_students_info: In this project, I want the program to be able to store, read, update and delete the personal information of fictional students.

Cheers.

Can you walk me through an example of how to reproduce the error you show above?

I was able to add a new entry and then put 0 in the input box to the left of the Delete button and click it with no errors showing.

Also, just to confirm, what is the user supposed to be able to do with the Delete button and the input to the left of it? Basically, what are you expecting DataStudents to look like after clicking Delete?

Sure! Maybe it’s better if I address your second question first. If you want to delete a student’s personal info, you can write his or her name on the input and delete the whole class where the data is stored. I do not know if I expected DataStudent to look like anything. With regard to the first question, the issue arises after I delete a student’s info and then try to use find: that’s when I get the Uncaught typeError message.

The reason you get that error message is because in the following line of your find function:

let foundName = DaraStudArr.find(({name}) => name === find2.value);

name is undefined.

Why? Because DaraStudArr is an empty array, so there is no object to destructure to give you a name property.

Why is DaraStudArr empty? Because you deleted the person in the following line of your deleteContent function:

delete DaraStudArr[classNumContainer.get(deleteInfo.value)];

Yes, Randell, got it. I just tried a new solution, which was to only delete the properties inside the class and find worked fine; however, the whole process was quite cumbersome, because I had to delete each property at a time. Nevertheless, is this the proper path, that is, to delete the properties?

Thanks for the help. I’m going to work on it!