0

I have a Json Doc which i get from my back end which looks like the one below. It has an emails Array which the doc under it has and email array. I need to get the index the email array is part of which has a match for an email address so i can update the doc. i used lodash before to search for a key in a array of docs before with _.find and _.indexOf but not sure how this would work in an Array of Array case.

{
  "_type": "email_campaign",
  "status": "Active",
  "start_date": "04/17/2020",
  "template_id": "template::0a2decdd-3acd-4661-9721-1a9ec0d039e6",
  "summary": "Update",
  "metrics": {
    "first_email_sent": "",
    "last_email_send": "2020-04-17T22:11:52.317Z",
    "nbr_of_emails": 185,
    "nbr_of_bounces": 1,
 },
 "history": {
    "created_on": "04/17/2020 13:24:33",
  },
  "emails": [
    {
      "email": [
        "[email protected]"
      ],
      "track_request": "track_request::da07bd4b-b03e-4ecc-9d90-32e85cdb5b3a",
      "tracking_nbr": "MD1dpjR6d"
    },
    {
      "email": [
        "[email protected]",
        "[email protected]",

      ],
      "track_request": "track_request::6f64cee1-d38e-4d68-94a2-c3c7d1287984",
      "tracking_nbr": "YM1sMRX3nl"
    },
    {
      "email": [
        "[email protected]"
      ],
      "track_request": "track_request::92606d4f-f9e6-457f-9156-167eb068f05b",
      "tracking_nbr": "gj6dwIyHdE"
    },

  ],
  "_id": "3ed76589-4063-49f6-a21e-9ca16981d102"
}

2 Answers 2

1

You could use findIndex and includes:

const index = docs.emails.findIndex(item => item.email.includes('[email protected]'))
Sign up to request clarification or add additional context in comments.

Comments

0

try this:

emailToFind="xxxxxxxxx"
var indexes=[]
var test= res.emails.map((el1,i1)=>{
  el.email.map((el2,i2)=>{
    if (el2===emailToFind){
      indexes.push(i1)
    }
  })
})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.