-
-
Save kobitoDevelopment/1093f8d0bd4a310477d06ad79b40c11e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 sample = [ | |
{ | |
id: 1, | |
name: "name1", | |
}, | |
{ | |
id: 2, | |
name: "name2", | |
}, | |
]; | |
// mapを使ってidが1のnameをupdateに変更 | |
const mapSample2 = sample.map((item) => { | |
if (item.id === 1) { | |
item.name = "update"; | |
return item; | |
} else { | |
return item; | |
} | |
}); | |
console.log(mapSample2); | |
// filterを使ってidが1オブジェクトを削除 | |
const filterSample = sample.filter((item) => { | |
if (item.id === 1) { | |
return false; | |
} else { | |
return true; | |
} | |
}); | |
console.log(filterSample); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment