Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. // 找出符合條件資料的 index
  2. const index = comments.findIndex(comment => comment.id === 823423);
  3. console.log(index);
  4.  
  5. // 方法1:splice
  6. comments.splice(index, 1);
  7.  
  8. // 方法2:slice
  9. const newComments = [
  10. ...comments.slice(0, index),
  11. ...comments.slice(index + 1)
  12. ];
  13.  
  14. console.table(comments);
  15. console.table(newComments);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement