Monday, February 12, 2018

using .concat and using the spread operator to flatten arrays into arrays in TypeScript

let yin: Array<string> = ["foo", "bar", "baz", "quz"];
let yang: Array<string> = ["doe", "ray", "me"];
let yinYang: Array<string> = [...yin, ...yang];
console.log(yinYang);

 
 

...does the same thing as:

let yin: Array<string> = ["foo", "bar", "baz", "quz"];
let yang: Array<string> = ["doe", "ray", "me"];
let yinYang: Array<string> = yin.concat(yang);
console.log(yinYang);

 
 

The .concat exists in JavaScript itself!

No comments:

Post a Comment