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

104
Views
cómo tomar un valor de un objeto anidado en los encabezados
 headers: { host: 'localhost:3000', connection: 'keep-alive', 'cache-control': 'max-age=0', 'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="101", "Google Chrome";v="101"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '"macOS"', 'upgrade-insecure-requests': '1', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36', Code: const user: User = req['user']; return { userAgent: { agent: req.headers.connection.reduce((el) => Object.fromEntries( Object.entries(el).map(([k, v]) => [k, Object.values(v)[0]]), ), ), }, headers: req.headers, }; } } I have to take user-agent from connection. I have used the map and reduce function but its says map cannot be used for string.

Si estoy haciendo req.headers.connection, solo obtengo "keep-alive"

también he usado. req.headers.connection[6], pero no obtuvo el resultado deseado.

el resultado deseado es obtener el agente de usuario de la conexión

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

0

req.headers.connection es un único elemento. Tal vez te estés confundiendo porque las otras claves de req.headers tienen comillas. Esto debería funcionar:

 return { userAgent: { agent: req.headers["user-agent"] }, headers: req.headers, };
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!