2d array splicing problems

I am creating a simple project where people can edit some information in the array. They can add and replace with spilce.

But I am unable to use splice on the 2d array, becos i keep getting undefined error.

Below is an example of my code

array[ ].splice(y,1, textbox.value);

x = the index of the array I want to splice.

y = the position in the array.

Every thing works well when I use numbers while splicing.

Eg = array[0].splice(1,1, textbox.value);

array[z].splice(y,1, textbox.value);

You will need to show more than that, you have not given enough infos for debugging

1 Like

here is my code

let gtIndex = arrMain.twoDIndexOf(renameMe.value)

let x = gtIndex[0];

let y = gtIndex[1];


Here is the console error

admin.js:229 Uncaught TypeError: Cannot read properties of undefined (reading 'splice')
    at xc (admin.js:229)
    at HTMLButtonElement.onclick (admin.html?

Every thing works well if I use just numbers throughout the code.

I want to edit infos on a site I am building for my portfolio with splice.

Is their a better way?


Try adding console.log(arrMain[x]) and see what’s the value

When I used only arrMain it worked well, but when i added the splice part I get an error.

I am trying to work with the info you have given
so please add console.log(arrMain[x]) and see what’s the value


The error was from my end.

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