js & array remove one item ways

js & array remove one item ways

// array remove one item ways

    let keys = [1,2,3,4,5,6,7];
    let key = 3;
    // keys.remove(key); ???
    let index = keys.indexOf(key);
    // keys = keys.splice(index, 1);
    // keys = keys.slice(index, index + 1);
    keys = keys.filter(icon => icon !== key);

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filterhtml

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reducecode

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slicehtm

let animals = ['ant', 'bison', 'camel', 'duck', 'elephant'];
 
console.log(animals.slice(4, 5));

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/spliceblog

let months = ['Jan', 'March', 'April', 'June'];
 
// remove one
months.splice(2, 1);
 
console.log(months);
// expected output: Array ['Jan', 'March', 'June']

https://www.cnblogs.com/xgqfrms/p/11039499.htmlip

相關文章
相關標籤/搜索