How do I remove an array item in TypeScript?

后端 未结 14 2305
渐次进展
渐次进展 2020-12-07 07:42

I have an array that I\'ve created in TypeScript and it has a property that I use as a key. If I have that key, how can I remove an item from it?

14条回答
  •  再見小時候
    2020-12-07 07:58

    You can try to get index or position of list or array first, then use for loop to assign current array to a temp list, filter out unwanted item and store wanted item back to original array

    removeItem(index) {
        var tempList = this.uploadFile;
        this.uploadFile = [];
    
        for (var j = 0; j < tempList.length; j++) {
          if (j != index)
            this.uploadFile.push(tempList[j]);
        }
      }
    

提交回复
热议问题