Javascript Array Multi-dimensional

Introduction

The following creates a chess board as a two-dimensional array of strings.

let board = [ /*from  w w w .  j  a va  2s. c o  m*/
  ['A','B','C'],
  ['P','P','P'],
  [' ',' ',' '],
  [' ',' ',' '],
  [' ',' ',' '],
  [' ',' ',' '],
  ['p','p','p'],
  ['r','n','b'] ]

console.log(board.join('\n') + '\n\n')

Using an array to tabulate a set of values

values = []// w  ww  . jav  a2 s.c  o  m
for (let x = 0; x < 10; x++){
 values.push([
  2 ** x,
  2 * x ** 2
 ])
}
console.table(values)



PreviousNext

Related