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

156
Views
Match key to find object data in JavaScript

I have an object like:

{
  sunday: {status: "open", opening_time: "11:30 am", closing_time: "12:00 pm"},
  monday: {status: "close", opening_time: "", closing_time: ""},
  tuesday: {status: "close", opening_time: "", closing_time: ""},
  wednesday: {status: "close", opening_time: "", closing_time: ""},
  thursday: {status: "close", opening_time: "", closing_time: ""},
  friday: {status: "close", opening_time: "", closing_time: ""},
  saturday: {status: "close", opening_time: "", closing_time: ""}
}

Also I have got the current data in a variable var curr = 'friday' . Now I need to find only the friday object from the collection which is friday: {status: "close", opening_time: "", closing_time: ""}.

How can I do that?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You can use like this.

let data = {
  sunday: {status: "open", opening_time: "11:30 am", closing_time: "12:00 pm"},
  monday: {status: "close", opening_time: "", closing_time: ""},
  tuesday: {status: "close", opening_time: "", closing_time: ""},
  wednesday: {status: "close", opening_time: "", closing_time: ""},
  thursday: {status: "close", opening_time: "", closing_time: ""},
  friday: {status: "close", opening_time: "", closing_time: ""},
  saturday: {status: "close", opening_time: "", closing_time: ""}
};
let curr = 'friday';
console.log(data[curr]);

about 4 years ago · Juan Pablo Isaza Report

0

Since its an object, do a check if the key exist. if yes use dot operator or square bracket to get value corresponding to the key.

let dict =  {
           sunday: {status: "open", opening_time: "11:30 am", closing_time: "12:00 pm"},
           monday: {status: "close", opening_time: "", closing_time: ""},
           tuesday: {status: "close", opening_time: "", closing_time: ""},
           wednesday: {status: "close", opening_time: "", closing_time: ""},
           thursday: {status: "close", opening_time: "", closing_time: ""},
           friday: {status: "close", opening_time: "", closing_time: ""},
           saturday: {status: "close", opening_time: "", closing_time: ""}
       }
var curr = 'friday';
if (curr  in dict)
{
   console.log(dict[curr ])
}
about 4 years ago · Juan Pablo Isaza Report

0

In JavaScript Object if you have key you can use normal index like myobj['key']

var myobj = {
  sunday: {status: "open", opening_time: "11:30 am", closing_time: "12:00 pm"},
  monday: {status: "close", opening_time: "", closing_time: ""},
  tuesday: {status: "close", opening_time: "", closing_time: ""},
  wednesday: {status: "close", opening_time: "", closing_time: ""},
  thursday: {status: "close", opening_time: "", closing_time: ""},
  friday: {status: "close", opening_time: "", closing_time: ""},
  saturday: {status: "close", opening_time: "", closing_time: ""}
}

console.log(myobj['friday']);

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!