What is the meaning of “foo(…arg)” (three dots in a function call)?

后端 未结 4 2092
南旧
南旧 2021-01-12 07:30

Can someone tell what is \"...\" in the below code in the \"Intro to Angular\" example?

getHeroes() {
    this.backend.getAll(Hero).then( (heroes: Hero[]) =&         


        
4条回答
  •  感动是毒
    2021-01-12 07:44

    It's a copy of the original array

    let args = [7, 3, 8];
    var [h] = args.reverse(); // args is now 8, 3, 7
    

    whereas

    var [h] = [...args].reverse(); // args is still 7, 3, 8
    

    It can also be used to specify the remaining values of an array

    var [first, ...rest] = args; // first = 7, rest = [3, 8]
    

提交回复
热议问题