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

186
Views
How to append multiple values in setstate for array object Reactjs

I want to append objects in my array using setState function. My initial variable looks like this:

columns1: [
        {
          title: "Sr. No.",
          render(text, record, index) {
            return {
              children: <div> {index + 1}</div>,
            };
          },
        },
        {
          title: "Account ID",
          dataIndex: "Accountid",
        },
        {
          title: "Alias",
          dataIndex: "Alias",
        },
      ],

Now, in a function I want to add 2 more objects in columns1:

const projCol = {
      title: "Projected Cost",
      dataIndex: "forecast_amount",
      key: "forecast_amount",
  },

  const projChange = {
          title: "Percentage Change",
          dataIndex: "%change",
          key: "%change",
   }

if I only wanted to add projCol I can do

this.setState((prevState) => {
      return {
        columns1: [...prevState.columns1,projCol],
      };
    });

but how can I add both projCol and projChange?

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

0

Just add one more element to the array like you do with projCol, separated by commas.

this.setState((prevState) => {
      return {
        columns1: [...prevState.columns1, projCol, projChange]
      };
  });
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!