How do I remove an array item in TypeScript?

后端 未结 14 2283
渐次进展
渐次进展 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 08:12

    let a: number[] = [];
    
    a.push(1);
    a.push(2);
    a.push(3);
    
    let index: number = a.findIndex(a => a === 1);
    
    if (index != -1) {
        a.splice(index, 1);
    }
    
    console.log(a);
    

提交回复
热议问题