Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- delete myArray[key];
- const index = myArray.indexOf(key, 0);
- if (index > -1) {
- myArray.splice(index, 1);
- }
- let foo_object // Item to remove
- this.foo_objects = this.foo_objects.filter(obj => obj !== foo_object);
- removeDocument(doc){
- this.documents.forEach( (item, index) => {
- if(item === doc) this.documents.splice(index,1);
- });
- }
- onDelete(id: number) {
- this.service.delete(id).then(() => {
- let index = this.documents.findIndex(d => d.id === id); //find index in your array
- this.documents.splice(index, 1);//remove element from array
- });
- event.stopPropagation();
- }
- arr.splice(2,1);
- arr.splice(arr.length,1);
- // Your key
- const key = 'two';
- // Your array
- const arr = [
- 'one',
- 'two',
- 'three'
- ];
- // Get either the index or -1
- const index = arr.indexOf(key); // returns 0
- // Despite a real index, or -1, use spread operator and Array.prototype.slice()
- const newArray = (index > -1) ? [
- ...arr.slice(0, index),
- ...arr.slice(index + 1)
- ] : arr;
- let updatedArray = [];
- for (let el of this.oldArray) {
- if (el !== elementToRemove) {
- updated.push(el);
- }
- }
- this.oldArray = updated;
- departments: string[] = [];
- removeDepartment(name: string): void {
- this.departments = this.departments.filter(item => item != name);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement