Hello thanks for the code it worked here. But I had to make two small corrections, I don't know if others may have the same error, in line 30 it was necessary to put the term 'undefined' with quotation marks.
And on line 36 it was giving an error here for me, so I disassembled it and it worked, I removed the part "params.length - 1" from inside the variable 'id' and everything worked.
But it still helped a lot, thank you very much.