Javascript Array col(j)

Description

Javascript Array col(j)

Array.prototype.col = function(j) {
  col = [];//from ww  w . j av a  2 s.c  om
  for(i=0; i<this.length; i++){
    col.push(this[i][j]);
  }
  return col;
}


Array.prototype.transpose = function() {
  transp = [];
  for(j=0; j<this[0].length; j++){
    transp.push(this.col(j));
  }
  return transp;
}

// a = [[1,2,3],[4,5,6],[7,8,9]];
// console.log(a.transpose());



PreviousNext

Related