Skip to content

Instantly share code, notes, and snippets.

@alegut
Created February 21, 2020 07:39
Show Gist options
  • Save alegut/366b1c05b6970341279880c05f3a5d6a to your computer and use it in GitHub Desktop.
Save alegut/366b1c05b6970341279880c05f3a5d6a to your computer and use it in GitHub Desktop.
Find And Replace The key-value Pair in an Array of Object
const personObject = [
{
"id":1,
"name": "A",
"experienceInYear": 5,
"designation" : "senior associate"
},
{
"id":2,
"name": "B",
"experienceInYear": 3,
"designation" : "associate"
},
{
"id":3,
"name": "C",
"experienceInYear": 6,
"designation" : "senior"
}
]
const res = personObject.map(p => p.experienceInYear >= 6 ? {...p,designation: "lead"} : p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment