Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

192
Views
how to get user_name from the title that has "eJx2" in it from this json array?

I wanna get user_name from one of these that have "eJx2" in it. I have this code but this code prints all of "user_name"s. I want to just get the user_name of those that have "eJx2" in it.

var titles = arry.data.map(el => el.title);
for (var k in titles) {
    var never = titles[k].includes('eJx2');
    if (never) {
        var names = arry.data.map(el => el.user_name);
        console.log(names);
    }
}

and this is the json :

   {
  data: [
    {
      id: '46475273517',
      user_name: 'testtwo',
      title: 'Hello this is my test for the eJx2',
      is_set: true
    },
    {
      id: '46471542013',
      user_name: 'testone',
      title: 'Hello this is my test for the eJx3',
      is_set: false
    },
    {
      id: '46474254233',
      user_name: 'testthree',
      title: 'Hello this is my test for the eJx7',
      is_set: false
    }
  ],
  pagination: {
    cursor: 'eyJiIjp7IkN1cnNvciI6ImV5SnpJam80TXpBeExqSTBNemcwTVRnME56WTVOQ3dpWkNJNlptRnNjMlVzSW5RaU9uUnlkV1Y5In0sImEiOnsiQ3Vyc29yIjoiZXlKeklqbzFOREV1T1RnMk56STNNall5TkRReE5Dd2laQ0k2Wm1Gc2MyVXNJblFpT25SeWRXVjkifX0'
  }
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Use array filter

array.data.filter(item => item.title.includes("eJx2"))

var array = {
  data: [
    {
      id: '46475273517',
      user_name: 'testtwo',
      title: 'Hello this is my test for the eJx2',
      is_set: true
    },
    {
      id: '46471542013',
      user_name: 'testone',
      title: 'Hello this is my test for the eJx3',
      is_set: false
    },
    {
      id: '46474254233',
      user_name: 'testthree',
      title: 'Hello this is my test for the eJx7',
      is_set: false
    }
  ],
  pagination: {
    cursor: 'eyJiIjp7IkN1cnNvciI6ImV5SnpJam80TXpBeExqSTBNemcwTVRnME56WTVOQ3dpWkNJNlptRnNjMlVzSW5RaU9uUnlkV1Y5In0sImEiOnsiQ3Vyc29yIjoiZXlKeklqbzFOREV1T1RnMk56STNNall5TkRReE5Dd2laQ0k2Wm1Gc2MyVXNJblFpT25SeWRXVjkifX0'
  }
}

var filteredData = array.data.filter(item => item.title.includes("eJx2"))

console.log(filteredData)

about 4 years ago · Juan Pablo Isaza Report

0

Use filter() to filter title have 'eJx2' and map() to get only user_name:

 const arry = {
  data: [
    {
      id: '46475273517',
      user_name: 'testtwo',
      title: 'Hello this is my test for the eJx2',
      is_set: true
    },
    {
      id: '46471542013',
      user_name: 'testone',
      title: 'Hello this is my test for the eJx3',
      is_set: false
    },
    {
      id: '46474254233',
      user_name: 'testthree',
      title: 'Hello this is my test for the eJx7',
      is_set: false
    }
  ],
  pagination: {
    cursor: 'eyJiIjp7IkN1cnNvciI6ImV5SnpJam80TXpBeExqSTBNemcwTVRnME56WTVOQ3dpWkNJNlptRnNjMlVzSW5RaU9uUnlkV1Y5In0sImEiOnsiQ3Vyc29yIjoiZXlKeklqbzFOREV1T1RnMk56STNNall5TkRReE5Dd2laQ0k2Wm1Gc2MyVXNJblFpT25SeWRXVjkifX0'
  }
}

const result = arry.data.filter(({title}) => title.includes("eJx2")).map(el => el.user_name)
console.log(result)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!