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

82
Views
Spread Operator for array of array

How to perform spread opration on salesuser array object. need to add ..salesuserstargetAmount:500, in that object

  {        
    "station": [
        {
            "stationname":"chennai",
            "stationtargetAmount":500,
            "salesusers":[
                {
                " salesusersname":"tester", 
                },         
         ]
        },
    {
            "stationname":"chennai22222",
           "stationtargetAmount":500,
            "salesusers":[
                {
                " salesusersname":"tester222222", 
                },         
         ]
        }
    ]
 }

Tried with

let  salesusertargetamt = "100"

 this.setState({
   salesusers: this.state.station.map((items) => {
   items.salesusers.map(el => (el.salesusersname !== "" ? { ...el, salesusertargetamt } : el))
  });
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

let  salesusertargetamt = "100"

 this.setState({
   salesusers: this.state.station.map((items) => {
    return items.salesusers.map(el => (el.salesusersname !== "" ? { ...el, stationtargetAmount: salesusertargetamt } : el))
  });
about 4 years ago · Juan Pablo Isaza Report

0

Curly braces ({) are tricky here because they both mean block of code and JavaScript object so you need to wrap them with ():

let  salesusertargetamt = "100";

 let obj = {        
    "station": [
        {
            "stationname":"chennai",
            "stationtargetAmount":500,
            "salesusers":[
                {
                " salesusersname":"tester", 
                },         
         ]
        },
    {
            "stationname":"chennai22222",
           "stationtargetAmount":500,
            "salesusers":[
                {
                " salesusersname":"tester222222", 
                },         
         ]
        }
    ]
 };
 
 let result = obj.station.map(items => ({
    ...items,
    salesusers: items.salesusers.map(user => (user.salesusersname !== "" ? {...user, salesusertargetamt} : user ))
 }))
 

 console.log(result);

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!