Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

224
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda