Skip to content

Commit 94b6cb5

Browse files
committed
Day 7 delete element from array, 2 methods
1 parent 5e546bb commit 94b6cb5

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

07 - Array Cardio Day 2/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@
4747
const commentId = comments.findIndex( comment => comment.id === 823423)
4848
console.log({commentId})
4949

50+
// Delete element from array by id
51+
52+
// Popular Redux method
53+
const newComments = [
54+
...comments.slice(0, commentId),
55+
...comments.slice(commentId + 1)
56+
]
57+
console.table(newComments)
58+
59+
// And normal use splice
60+
comments.splice(commentId, 1)
61+
console.table(comments)
62+
5063
</script>
5164
</body>
5265
</html>

0 commit comments

Comments
 (0)