How to remove row in 2d array in javascript

后端 未结 6 1663
醉梦人生
醉梦人生 2021-02-05 19:42

How to remove row in two dimensional array in JavaScript with row number. If I want to delete all elements in row number 4 then how can do it??

6条回答
  •  灰色年华
    2021-02-05 20:14

    Just call the splice(4, 1) method, when 4 is row number and 1 is number of rows to remove -

    twoDimensionalArray.splice(4, 1); // remove 4th row
    

    Also shift() and pop() are very handy methods which remove first and last rows accordingly -

    twoDimensionalArray.shift(); // to remove first row
    twoDimensionalArray.pop(); // to remove last row
    

提交回复
热议问题