To add a person to a window and push the person to an array in one line, you can use the following code:
index.tsx124 chars3 lines
This code uses an immediately invoked function expression (IIFE) to add the person object to the window
object and return the updated array of persons. If the persons
array does not exist on the window
object, it is created first. The concat
method is used to append the new person object to the array.
Note that this code uses ES6 arrow functions and the functional programming style to create a concise and expressive one-liner.
gistlibby LogSnag