What do these three dots in React do?

前端 未结 29 3153
不思量自难忘°
不思量自难忘° 2020-11-21 23:53

What does the ... do in this React (using JSX) code and what is it called?



        
29条回答
  •  日久生厌
    2020-11-22 00:26

    In a short, the three dots ... is a spread operator in ES6(ES2015). Spread operator will fetch all the data.

    let a = [1, 2, 3, 4];
    let b = [...a, 4, 5, 6];
    let c = [7,8,...a];
    
    
    console.log(b);
    

    Will give the result [1,2,3,4,5,6]

    console.log(c);
    

    Will give the result [7,8,1,2,3,4]

提交回复
热议问题