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

239
Views
how to foreach the object key in javascript

I define a object like this using Javacript:

const city = {
  "北京市": ["北京市"],
  "天津市": ["天津市"],
  "上海市": ["上海市"],
  "重庆市": ["重庆市"],
  "香港": ["香港"],
  "澳门": ["澳门"],
  "台湾省": ["台湾省"]
};

now I want to foreach the city key with other strings I defined like this:

const region = [
  "北京市",
  "天津市",
];

but I did not know how to foreach the key of city, what I want to do may look like this:

var options = region.map(function (item){
    
     children = city.map(function (itemc){
       if(itemc.key === item){
         return itemc.value
       }
     });
      return ({
        label: item,
        children: children
      });
    });

but the city did not contains keys or index for me to compare, what should I do to make it work?

about 4 years ago · Juan Pablo Isaza
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!