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

102
Views
Remove array bracket before pushing to an array
[
  [
    {
      "id": "5d52eaa88c31223a0ea27df7",
      catalogues: [Array]
    }
  ],
  [
    {
      "id": "5d52f17a8c31223a0ea27e38",
      catalogues: [Array]
    }
  ],
  [
    {
      "id": "5d52f17a8c31223a0ea27e32",
      catalogues: [Array]
    }
  ],
  [
    {
      "id": "5d52f17a8c31223a0ea27e31",
      catalogues: [Array]
    }
  ]
]

Make a single array before pushing it to another array containing a JSON object. Can I make it as a json object by removing square bracket before pushing to a array.

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

0

You can use flat.

const myArray = [
      [
        {
          id: '5d52eaa88c31223a0ea27df7',
          catalogues: [Array]
        }
      ],
      [
        {
          id: '5d52f17a8c31223a0ea27e38',
          catalogues: [Array]
        }
      ],
    [
        {
          id: '5d52f17a8c31223a0ea27e32',
          catalogues: [Array]
        }
      ],
[
    {
      id: '5d52f17a8c31223a0ea27e31',
      catalogues: [Array]
    }
  ]
    ]
    
console.log(myArray.flat());

about 4 years ago · Juan Pablo Isaza Report

0

Your object is much larger than with [Array] standing for [...] - several elements. For the purpose of the demo I have replaced every occurrence of [Array] with [].

Use the JSON.stringify to convert the whole data into a JSON string as follows - no need to remove any square brackets:

const input = [ [ { id: '5d52eaa88c31223a0ea27df7', catalogues: [] } ], [ { id: '5d52f17a8c31223a0ea27e38', catalogues: [] } ], [ { id: '5d52f17a8c31223a0ea27e32', catalogues: [] } ], [ { id: '5d52f17a8c31223a0ea27e31', catalogues: [] } ] ],

      output = JSON.stringify(input);

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!