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

124
Views
Add new attribute for the JSON Array List

I need to add new attribute for JSON object. currently my code like as below

 let abc  =  this.dataSource.data;
            console.log(abc);

console log data set like below

{
    "result": [
        {
            "id": 210,
            "temp": "210",
            "city": "colombo",
            "status": "waiting"
        },
        {
             "id": 211,
            "temp": "212",
            "city": "colombo2",
            "status": "waiting"
        },
    ]
}

I need to add new attribute for the JSON object. My expect JSON object like below

  {
    "result": [
        {
            "id": 210,
            "temp": "210",
            "city": "colombo",
            "status": "waiting"
        "select": false,
        },
        {
             "id": 211,
            "temp": "212",
            "city": "colombo2",
            "status": "waiting",
            "select": false,
        },
    ]
  }

I tried to do it using this,

abc = {...abc,select:false}

but it did not work. How I do this

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

0

Just use map:

const data = {
"result": [
    {
        "id": 210,
        "temp": "210",
        "city": "colombo",
        "status": "waiting"
    },
    {
         "id": 211,
        "temp": "212",
        "city": "colombo2",
        "status": "waiting"
    },
]
}
  
  function formatData(data){
    return data.result.map(res=> ({...res, select: false}))
  }

console.log(formatData(data))

about 4 years ago · Juan Pablo Isaza Report

0

You have to specify the correct path and iterate over the result array:

for (let i=0; i < abc.result.length; i++) {
    abc.result[i].select = false
} 
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!