1

I want to populate an autocomplete search box.

I am using this, but is there a better way?

var array1 = [
  ['a', 'b', 'c'],
  ['d', 'e', 'f'],
  ['g', 'h', 'i']
];

console.log(array1[0].concat(array1[1], array1[2]));
Eddie
  • 26,593
  • 6
  • 36
  • 58
Ashley Howard
  • 63
  • 1
  • 8

1 Answers1

2

One option is using flat()

var array1 = [
  ['a', 'b', 'c'],
  ['d', 'e', 'f'],
  ['g', 'h', 'i']
];

console.log( array1.flat() );

Or concat and spread syntax

var array1 = [
  ['a', 'b', 'c'],
  ['d', 'e', 'f'],
  ['g', 'h', 'i']
];

console.log( [].concat(...array1) )
Eddie
  • 26,593
  • 6
  • 36
  • 58