Last active
January 9, 2018 07:47
-
-
Save sekky0905/680afd95a266e67a37a114641d1a81ac to your computer and use it in GitHub Desktop.
Javascriptで指定した配列の要素を削除する ref: https://qiita.com/Sekky0905/items/598b47fea2106b8c140e
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
before : array = 0,1,2,3,4 | |
after : array = 0,2,3,4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const array = [0, 1, 2, 3, 4]; | |
console.log(`before: array = ${array}`); | |
const newArray = array.filter(n => n !== 1); | |
console.log(`after: array = ${newArray}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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