Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 找出符合條件資料的 index
- const index = comments.findIndex(comment => comment.id === 823423);
- console.log(index);
- // 方法1:splice
- comments.splice(index, 1);
- // 方法2:slice
- const newComments = [
- ...comments.slice(0, index),
- ...comments.slice(index + 1)
- ];
- console.table(comments);
- console.table(newComments);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement