是这样的,假如我有一个三级的数组datas,想通过ts把它简化,返回最里面那一层的数据,然后在模板上面直接使用。不怎么了解forEach的使用,在实践中报错了。初学者,希望大神勿喷,百度了forEach,没有详细说明。
小伙看你根骨奇佳,潜力无限,来学PHP伐。
forEach It seems that it is not from TS, but from ES. Usage is very simple
forEach
var a = [1, 2, 3] a.forEach(function (e) { console.log(e); });
This way you will get 1, 2, 3
If it is a multi-level array,
var b = [[1, 2], [3, 4], [5, 6]]; b.forEach(function (elementOutside) { elementOutside.forEach(function (elementInside) { console.log(elementInside); }) })
This way you get 1, 2, 3, 4, 5, 6
I don’t know what your specific needs are. . It would be best to add some additional explanation. Maybe what you need is not forEach 而是 map but map
map
Reference: ES: https://developer.mozilla.org...
TS: https://www.typescriptlang.or...
forEach
It seems that it is not from TS, but from ES. Usage is very simpleThis way you will get 1, 2, 3
If it is a multi-level array,
This way you get 1, 2, 3, 4, 5, 6
I don’t know what your specific needs are. . It would be best to add some additional explanation. Maybe what you need is not
forEach
而是map
butmap
Reference:
ES: https://developer.mozilla.org...
TS: https://www.typescriptlang.or...