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

237
Views
React - Unable to sort an object

I am trying to sort an object alphabetically in react/javascript in a java application Im not sure how to do it and i keep getting the same error.

Here is the function code and i am trying to sort both build and catalog objects

import React, { useContext } from 'react'
import DetailHeader from '../detailHeader/DetailHeader'
import style from './installedOptions.scss';
import { MainContext } from '../../../Context';
import Grid from '../../common/grid/Grid';

function InstalledOptions() {

const dsContext: any = useContext(MainContext)
const build = dsContext.dsState.installedOptions.premiumPlus;
const catalog = dsContext.dsState.installedOptions.premium;

return (
    <div className={style.header} id="installedOptions">
        <DetailHeader heading="INSTALLED OPTIONS" />
        {
            build.header && <div className={style.grid}>
                <Grid header={[build.header]} tableData={[build.details]} />
                <Grid header={[catalog.header]} tableData={[catalog.details]} />
            </div>
        }

    </div>
  )
}

export default InstalledOptions

what i have tried that throws errors

const sortedCatalog = [...catalog ]

sortedCatalog.sort((a, b) => {
    if (a.name < b.name) {
        return -1;
    }
    if (a.name > b.name) {
        return 1;
    }
    return 0;
});

// console.log(sortedCatalog)

error

bundle.js:27 TypeError: Invalid attempt to spread non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.

im at a loss on how to sort alphabetically. Thanks in advance

about 4 years ago · Juan Pablo Isaza
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!