Answers for "how to append to array in typescript"

3

how to add an element to a Typescript array

your_array.push(the_element);
Posted by: Guest on March-16-2020
0

react typescript append to array

interface IState {
  newTask: string;
  tasks: Array<ITask>;
}

addTask(name:string) {
  const newTask: ITask = {name, done: false}
  this.setState((prevState) => ({
    tasks: [...(prevState.tasks ?? []), newTask]
  }));
}
Posted by: Guest on March-15-2022

Code answers related to "how to append to array in typescript"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language