Delete a list of columns in a 2d array using java script

I need to delete some columns in a 2d array. The list is named as hiddenCols

var array = [
  ["a", "b", "c"],
  ["a", "b", "c"],
  ["a", "b", "c"]
]

hiddenCols = [3, 1] // these are pos and not indexes
for (var j = 0; j < array.length; j++) {
  for (var i = 0; i < hiddenCols.length; i++) {

    array[j].splice(hiddenCols[i], hiddenCols[i])
  }
}
console.log(JSON.stringify(array));

The expected result is var array = [["b"],["b"],["b"]];

52 thoughts on “Delete a list of columns in a 2d array using java script”

Leave a Comment