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

133
Views
Javascript Transformation Missing Objects

Hi I am transforming objects

I have write the following program to add newName in the array

If you take a look resultedEvents, categoryName and name is missing in the result.

const result2 = {
    "resultedEvents": [
        {
            "categoryName": "Football",
            "name": "Arsenal vs Aston Villa",
            "resultedMarkets": [
                {
                    "name": "Asian Handicap",
                },
                
      ]
    },
        {
            "categoryName": "Football",
            "name": "Arsenal vs Aston Villa (Live)",
            "resultedMarkets": [
                {
                    "name": "Asian Handicap -0.5 (1-3)",
        }
      ]
    }
    ]
}

const data2= result2.resultedEvents.map(items => {
    const newResult = items.resultedMarkets.map(function (item) {
      const newName = item.name.replace(/( -?\d+([.,]\d+)?)/g, "");
      return {...item,  newName};
    })
    return {  resultedMarkets: newResult  }
  }
);

console.log(data2)

Above program is giving me following

Output

[
    {
        "resultedMarkets": [
            {
                "name": "Asian Handicap",
                "newName": "Asian Handicap"
            }
        ]
    },
    {
        "resultedMarkets": [
            {
                "name": "Asian Handicap -0.5 (1-3)",
                "newName": "Asian Handicap (1-3)"
            }
        ]
    }
]

Expected

{
    "resultedEvents": [{
            "categoryName": "Football",
            "name": "Arsenal vs Aston Villa",
            "resultedMarkets": [{
                    "name": "Asian Handicap",
                    "newName": "Asian Handicap"
                }

            ]
        },
        {
            "categoryName": "Football",
            "name": "Arsenal vs Aston Villa (Live)",
            "resultedMarkets": [{
                "name": "Asian Handicap -0.5 (1-3)",
                "newName": "Asian Handicap (1-3)"
            }]
        }
    ]
}

Please help me to solve this issue I just want to add newName in the result, rest should be as it is

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

0

you are returning only resultedMarkets in your outer map

just add ...items like this

const result2 = {
    "resultedEvents": [
        {
            "categoryName": "Football",
            "name": "Arsenal vs Aston Villa",
            "resultedMarkets": [
                {
                    "name": "Asian Handicap",
                },
                
      ]
    },
        {
            "categoryName": "Football",
            "name": "Arsenal vs Aston Villa (Live)",
            "resultedMarkets": [
                {
                    "name": "Asian Handicap -0.5 (1-3)",
        }
      ]
    }
    ]
}

const data2= result2.resultedEvents.map(items => {
    const newResult = items.resultedMarkets.map( item => {
      const newName = item.name.replace(/( -?\d+([.,]\d+)?)/g, "");
      return {...item,  newName};
    })
    return {...items,  resultedMarkets: newResult  }
  }
);

console.log(data2)

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!