remove item from stored array in angular 2

前端 未结 11 1934
长发绾君心
长发绾君心 2020-12-23 02:34

I want to remove an item from a stored array in angular 2, with Type Script. I am using a service called Data Service, the DataService Code:

export cl         


        
11条回答
  •  忘掉有多难
    2020-12-23 03:23

    Don't use delete to remove an item from array and use splice() instead.

    this.data.splice(this.data.indexOf(msg), 1);
    

    See a similar question: How do I remove a particular element from an array in JavaScript?

    Note, that TypeScript is a superset of ES6 (arrays are the same in both TypeScript and JavaScript) so feel free to look for JavaScript solutions even when working with TypeScript.

提交回复
热议问题