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

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.

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.

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!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.