Skip to content

Instantly share code, notes, and snippets.

@sekky0905
Last active January 9, 2018 07:47
Show Gist options
  • Save sekky0905/680afd95a266e67a37a114641d1a81ac to your computer and use it in GitHub Desktop.
Save sekky0905/680afd95a266e67a37a114641d1a81ac to your computer and use it in GitHub Desktop.
Javascriptで指定した配列の要素を削除する ref: https://qiita.com/Sekky0905/items/598b47fea2106b8c140e
const array = [0, 1, 2, 3, 4];
console.log(`before : array = ${array}`);
array.forEach((item, index) => {
if(item === 1) {
array.splice(index, 1);
}
});
console.log(`after : array = ${array}`);
before : array = 0,1,2,3,4
after : array = 0,2,3,4
const array = [0, 1, 2, 3, 4];
console.log(`before: array = ${array}`);
const newArray = array.filter(n => n !== 1);
console.log(`after: array = ${newArray}`);
before : array = 0,1,2,3,4
after : array = 0,2,3,4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment