Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. delete myArray[key];
  2.  
  3. const index = myArray.indexOf(key, 0);
  4. if (index > -1) {
  5. myArray.splice(index, 1);
  6. }
  7.  
  8. let foo_object // Item to remove
  9. this.foo_objects = this.foo_objects.filter(obj => obj !== foo_object);
  10.  
  11. removeDocument(doc){
  12. this.documents.forEach( (item, index) => {
  13. if(item === doc) this.documents.splice(index,1);
  14. });
  15. }
  16.  
  17. onDelete(id: number) {
  18. this.service.delete(id).then(() => {
  19. let index = this.documents.findIndex(d => d.id === id); //find index in your array
  20. this.documents.splice(index, 1);//remove element from array
  21. });
  22.  
  23. event.stopPropagation();
  24. }
  25.  
  26. arr.splice(2,1);
  27.  
  28. arr.splice(arr.length,1);
  29.  
  30. // Your key
  31. const key = 'two';
  32.  
  33. // Your array
  34. const arr = [
  35. 'one',
  36. 'two',
  37. 'three'
  38. ];
  39.  
  40. // Get either the index or -1
  41. const index = arr.indexOf(key); // returns 0
  42.  
  43.  
  44. // Despite a real index, or -1, use spread operator and Array.prototype.slice()
  45. const newArray = (index > -1) ? [
  46. ...arr.slice(0, index),
  47. ...arr.slice(index + 1)
  48. ] : arr;
  49.  
  50. let updatedArray = [];
  51. for (let el of this.oldArray) {
  52. if (el !== elementToRemove) {
  53. updated.push(el);
  54. }
  55. }
  56. this.oldArray = updated;
  57.  
  58. departments: string[] = [];
  59.  
  60. removeDepartment(name: string): void {
  61. this.departments = this.departments.filter(item => item != name);
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement