Skip to content

Instantly share code, notes, and snippets.

@hyber1z0r
Last active August 10, 2020 19:45
Show Gist options
  • Save hyber1z0r/e29df4cb3d9cfab8c1e0d3e373701967 to your computer and use it in GitHub Desktop.
Save hyber1z0r/e29df4cb3d9cfab8c1e0d3e373701967 to your computer and use it in GitHub Desktop.
type Todo = {
id: number;
title: string;
completed: boolean;
}
const todos: Todo[] = [
{ id: 1, title: 'Buy nachos', completed: false },
{ id: 2, title: 'Buy avocado', completed: true },
{ id: 3, title: 'Buy ground beef', completed: false },
];
let completedTodos: Todo[] = [] as Todo[];
for (let i = 0; i < todos.length; i++) {
if (todos[i].completed) {
completedTodos.push(todos[i]);
}
}
console.log(completedTodos); // [{ id: 2, title: 'Buy avocado', completed: true }]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment