search

Home  >  Q&A  >  body text

angular.js - use of ts forEach

This is like this, if I have a three-level array datas, I want to simplify it through ts, return the data of the innermost layer, and then use it directly on the template.
I don’t know much about the use of forEach, and I got an error in practice. Beginners, I hope the masters don’t complain. Baidu has forEach without detailed explanation.

伊谢尔伦伊谢尔伦2782 days ago706

reply all(1)I'll reply

  • 仅有的幸福

    仅有的幸福2017-05-15 17:09:13

    forEach It seems that it is not from TS, but from ES. Usage is very simple

    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

    Reference:
    ES: https://developer.mozilla.org...

    TS: https://www.typescriptlang.or...

    reply
    0
  • Cancelreply