ES6 adds the of function to Array to convert one or more values into an array using the explicit meaning in one.
Because when constructing an array with new Array(), there is duality.
During construction, pass a parameter to indicate how large an array is generated.
During construction, multiple parameters are passed, each parameter is an element of the array.
const arr1 = new Array() const arr2 = new Array(5) const arr3 = new Array(1, 3, 'White', {p1: 'v1'}) ('%s', (arr1)) ('%s', (arr2)) ('%s', (arr3))
result:
[] [null,null,null,null,null] [1,3,"White",{"p1":"v1"}]
The () method added to ES6 has only one meaning, and the parameter of of represents the elements of the array after being captured.
const arr4 = () const arr5 = (5) const arr6 = (1, 3, 'White', {p1: 'v1'}) ('%s', (arr4)) ('%s', (arr5)) ('%s', (arr6))
result:
[] [5] [1,3,"White",{"p1":"v1"}]
This is the benefit of generating arrays with of, and the meaning is consistent.
The above usage (example explanation) based on ES6 is all the content I share with you. I hope you can give you a reference and I hope you can support me more.