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

135
Views
Las claves Object.Values representan todo en una línea en lugar de una línea por elemento
import {useState, useEffect } from 'react' import axios from 'axios' const Countries = ({searchedCountries}) => { console.log(searchedCountries.map(c => c.languages)) if (searchedCountries.length >= 10) { return ( <div> <p>too many countries to list, please narrow your search</p> </div> ) } if (searchedCountries.length === 1) { return ( <div> capital: {searchedCountries.map(c => <p>{c.capital}</p>)} area: {searchedCountries.map(c => <p>{c.area}</p>)} <h2>Languages</h2> <ul> {searchedCountries.map(c => <li>{Object.values(c.languages)}</li>)} </ul> {searchedCountries.map(c => <img src={Object.values(c.flags)[0]} /> )} </div> ) } return ( <ul> {searchedCountries.map(c => <li>{c.name.common}</li>)} </ul> ) } const App = () => { const [countries, setCountries] = useState([]) const [newSearch, setNewSearch] = useState('') const handleSearchChange = (event) => { setNewSearch(event.target.value) } const searchedCountries = countries.filter(c => c.name.common.includes(newSearch)) useEffect(() => { console.log('effect') axios .get('https://restcountries.com/v3.1/all') .then(response => { console.log('promise fulfilled') setCountries(response.data) }) }, []) return ( <div> <div><p>find countries</p><input value={newSearch} onChange={handleSearchChange} /></div> <div> <h2>countries</h2> <Countries searchedCountries={searchedCountries} /> </div> </div> ) } export default App;

Estoy tratando de enumerar los idiomas de cada país en mi aplicación, sin embargo, los idiomas se muestran así:

-InglésSuecoItaliano

en lugar de así:

  • inglés
  • sueco
  • italiano

¿Alguien sabe cómo representar cada uno de los Object.values(c.lenaguages) en su propia línea en lugar de agruparlos en una sola línea?

Gracias.

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

0

Estás pasando una matriz ( Obect.values(c.languages) ) en un solo <li> que React aplana a una cadena.

 <ul> {searchedCountries.map(c => <li>{Object.values(c.languages)}</li>)} </ul>

En su lugar, deberá map() la matriz de valores.

 <ul> { searchedCountries.map(c => <li> <ul> {Object.values(c.languages).map(l => <li>{l}</li>)} </ul> </li> ) } </ul>
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!