0

JSON STRUCTURE

 "applications" : [
    {
        "applicantID" : "607187fedf225c1d80cd0e7d", 
        "applicationMessage" : "bb", 
        "applicantUserName" : "alaa21", 
        "postResponse" : "still"
    }, 
    {
        "applicantID" : "6060dfde2607d52d1499c189", 
        "applicationMessage" : "ee", 
        "applicantUserName" : "taher", 
        "postResponse" : "still"
    }
], 

i have the "applicantID" as parameters and i want to access "applications" and find the object that has that "applicantID" and modify the string "postResponse" of that object . I'm using MERN Stack for this project

1 Answers1

0

You can accomplish this with the .find() array method, like this:

const data = {
  applications: [{
      applicantID: '607187fedf225c1d80cd0e7d',
      applicationMessage: 'bb',
      applicantUserName: 'alaa21',
      postResponse: 'still'
    }, {
      applicantID: '6060dfde2607d52d1499c189',
      applicationMessage: 'ee',
      applicantUserName: 'taher',
      postResponse: 'still'
    }
  ]
};

const findApplication = id => data.applications.find(a => a.applicantID === id)

console.log(findApplication('6060dfde2607d52d1499c189'));
Brandon McConnell
  • 5,776
  • 1
  • 20
  • 36