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]));
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]));
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) )