简体   繁体   中英

How to remove 1 element from array in typescipt?

I thought it doing like this:

 const months2 = ['Jan', 'March', 'April', 'June']; console.log(months2.splice(3, 1));

output: [ 'June' ]

You actually have it exactly right. Array.splice removes elements from the existing array and returns the elements that were removed.

const months2 = ['Jan', 'March', 'April', 'June'];
console.log(months2.splice(3, 1)); // Output: ['June']
console.log(months2); // Output: ['Jan', 'March', 'April']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM