繁体   English   中英

如何从 typescript 中的嵌套数组中获取数组

[英]How to get array from nested array in typescript

如何获取嵌套数组

 const array = arrayResult.map((loc) => loc.someOptions.map(options => {return options.someOptions}));

console.log(array);

我需要从嵌套数组中获取数组,

if (array.flat().includes('two')) {
  console.log("hello");
}

实际 output:

'string[][]' 类型不存在属性 'flat'。

预期 output:['一','二']“你好”

您可以使用array#flat()展平阵列,然后检查阵列中的two

 const array = [ ['one'], ['two']]; if (array.flat().includes('two')) { console.log("hello"); }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM