GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing basarat.gitbook.io — Spread Operator | TypeScript Deep Dive The main objective of the spread operator is to spread the elements of an array or object. This is best explained with examples. ApplyA common use case is to spread an array into the function arguments. Previously you would need to use Now you can do this simply by prefixing the arguments with Here we are spreading the DestructuringWe've already seen one usage of this in destructuring: The motivation here is to simply make it easy for you to capture the remaining elements of an array when destructuring. Array AssignmentThe spread operator allows you to easily place an expanded version of an array into another array. This is demonstrated in the example below: You can put the expanded array in at any position, and get the effect you'd expect: Object spreadYou can also spread an object into another object. A common use case is to simply add a property to an object without mutating the original: For objects, the order of where you put the spread matters. This works something like Another common use case is a simple shallow extend: Summary
Last updated |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |