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

176
Views
Object.keys devuelve una matriz vacía

Mi objeto tiene claves pero Object.keys() inesperadamente devuelve una matriz vacía.

Tengo el siguiente código en mi src/components/Projects.jsx

 import React from 'react' import {Cards} from "./Cards" export const Projects = (props) => { let starsCount = {}; const [returned,setReturned] = React.useState(false); //monitors if api has returned the data fetch('https://api.github.com/users/USERNAME_HERE/repos', { headers: { 'Accept' : 'application/vnd.github.v3+json' }}) .then(response => response.json()) .then( data => { for(let i=0;i < data.length;i++) { //if name of repo is "repo0" or "repo1" or "repo2" then add it to //object with total stars count as it key // example :- // starsCount = {"repo1" : 5, "repo2" : 9, "repo3" : 2} if(data[i].name == "repo0" || data[i].name=="repo1"|| data[i].name == "repo2"){ starsCount[data[i].name] = data[i].stargazers_count; } } setReturned(true); }) .catch( error => console.error(error)); returned ? console.log(starsCount,"keys are -> ",Object.keys(starsCount)) : {}; return ( <> // render loading screen until api returns data {(returned) ? <Cards> : <Loading/>} </> ) }

Este código registra el starsCount de estrellas como se esperaba, pero registra una matriz de claves vacía.

Esto es lo que registra:

 Object { "repo0" : 5, "repo1" : 9, "repo2":3} keys are -> Array []

También intenté usar Object.getOwnPropertyNames() pero sin suerte.

¿Qué estoy haciendo mal?

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!