Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

260
Visualizações
Iterating objects in React JS

What is the Error in the below code? I tried to iterate over the array of objects using the map. but I am receiving an error. Please find attached the code for reference.

import "./styles.css";

export default function App() {
const sample = [{
samplePath : "/website",
 par:{
  abc:"123",
  def: "678",
  ghi:"456"}
}];

const createURL = (re)=> {

const q = Object.entries(re.par)
    .map(([key, value]) => key +'='+value).join("&");

return "?"+ q;
}

console.log(createURL(sample));

return (
  <div className="App">
    <h1>Hello CodeSandbox</h1>
    <h2>Start editing to see some magic happen!</h2>
  </div>
);
}

I am receiving the following error error

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You're trying to call Object.entries on re.par. In this case, re is an array, so calling .par on it returns undefined. I'm not sure what your desired result is, but if you access the first element in the array and then .par, maybe that's what you're after?

const sample = [{
samplePath : "/website",
 par:{
  abc:"123",
  def: "678",
  ghi:"456"}
}];

const createURL = (re)=> {

const q = Object.entries(re.par)
    .map(([key, value]) => key +'='+value).join("&");

return "?"+ q;
}

console.log(createURL(sample[0]));

about 4 years ago · Juan Pablo Isaza Relatório

0

In your example sample is an array, containing one object.

So, either, remove the [] such that sample is an object like you are referring to it in your code. Or, Object.entries(re[0].par)

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda