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

121
Views
Need to return objects containing the key which referred from array of objects

I am trying to return the objects which has key of submittedDate. But if i am trying with find() It's returning only the first object. And for map it's returning undefined for object not having submittedDate key. Please find my code with data and also the result I want. thanks in advance.

    const data = [
        {   
            id: '1',
            name: 'Tully Stark',
            submittedData:'mmmmm'
        },
        {
            id:'2',
            name: 'Nalani Romanova',
        },
         {
            id:'3',
            name: 'Nalani Romanova',
            submittedData:'mmmmm'
        }
    ]  
    
    const submitDate = data.find(item => item.submittedData)
    
    console.log(submitDate)

data to return

const returnData = [
    {   
        id: '1',
        name: 'Tully Stark',
        submittedData:'mmmmm'
    },
     {
        id:'3',
        name: 'Nalani Romanova',
        submittedData:'mmmmm'
    }
]  
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

the .find by definition only returns the first matching object.

Array.prototype.find()
The find() method returns the value of the first element in the provided array that satisfies the provided testing function. If no values satisfy the testing function, undefined is returned.

You need to use .filter

const submitDate = data.filter(item => item.submittedData)

const data = [{
    id: '1',
    name: 'Tully Stark',
    submittedData: 'mmmmm'
  },
  {
    id: '2',
    name: 'Nalani Romanova',
  },
  {
    id: '3',
    name: 'Nalani Romanova',
    submittedData: 'mmmmm'
  }
]

const submitDate = data.filter(item => item.submittedData)

console.log(submitDate)

about 4 years ago · Juan Pablo Isaza Report

0

You can use Array.filter(), this will return all matching items.

const data = [ { id: '1', name: 'Tully Stark', submittedData:'mmmmm' }, { id:'2', name: 'Nalani Romanova', }, { id:'3', name: 'Nalani Romanova', submittedData:'mmmmm' } ]

const submitDate = data.filter(item => item.submittedData)
console.log(submitDate)
.as-console-wrapper { max-height: 100% !important; top: 0; }

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!