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

150
Views
Trying to return values with their key name from nested JSON array

I am trying to return values with their key name from nested JSON array

resData =[
  {
    _index: 'web',
    _type: 'event',
    _id: 'web+0+93',
    _score: null,
    _source: {
      'os-name': 'Windows',
      'browser-version': '90.0',
      'os-version': '10',

    },
    sort: [ '20210729T05:48:03Z' ]
  }
]
resData[0]._source["os-name"=>"os-name", 'browser-version'=>'90.0', 'browser-version': '90.0'];

but giving this error

SyntaxError: Malformed arrow function parameter list

Expected Output:

'os-name': 'Windows',
'browser-version': '90.0',
'os-version': '10'
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

This can be done as follows:

const resData =[
  {
    _index: 'web',
    _type: 'event',
    _id: 'web+0+93',
    _score: null,
    _source: {
      'os-name': 'Windows',
      'browser-version': '90.0',
      'os-version': '10'
    },
    sort: [ '20210729T05:48:03Z' ]
  }
];

const result = Object.entries(resData[0]._source)
                  .map(e => e[0] + ': ' + e[1])
                  .join('\n');

console.log(result);

about 4 years ago · Juan Pablo Isaza Report

0

const resData = [
  {
    _index: 'web',
    _type: 'event',
    _id: 'web+0+93',
    _score: null,
    _source: {
      'os-name': 'Windows',
      'browser-version': '90.0',
      'os-version': '10'
    },
    sort: [ '20210729T05:48:03Z' ]
  }
];

const output = Object.entries(resData[0]['_source'])
                     .map(([key, value]) => `${key}: ${value}`)
                     .join(',\n');

console.log(output);

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!