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

123
Views
Javascript array object return empty array

I try to filter jsonplaceholder comments to get by id but return empty array

axios.get('https://jsonplaceholder.typicode.com/comments').then((result) => {

 // const arr = _.find(result.data, { postID: 1});
 // console.log(arr);
 console.log(result.data.filter(x => x.postID === 1))

}).catch((err) => {
 console.log(err);
});
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Change postID by postId:

console.log(result.data.filter(x => x.postId === 1))

about 4 years ago · Juan Pablo Isaza Report

0

Log both the result data and the post id property type. So it could either be an absence of data from the response in the request or it could be a flawed comparison because of the "===" operandi

about 4 years ago · Juan Pablo Isaza Report

0

You're comparing postID instead of postId.

Working example at Codesandbox

axios
  .get("https://jsonplaceholder.typicode.com/comments")
  .then((result) => {
    // const arr = _.find(result.data, { postID: 1});
    // console.log(arr);
    console.log(result.data.filter((x) => x.postId === 1));
  })
  .catch((err) => {
    console.log(err);
  });

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!