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

124
Views
findindex return -1 Aunque la matriz no está vacía

Uso la función getMovie() para obtener los datos en la matriz a través de la identificación y en los "teatros" los datos se me devuelven correctamente, pero en "tendencia o popular" no devuelve ningún dato y el valor del índice es -1, aunque la matriz no está vacía

 export class MovieComponent implements OnInit { type = ''; id = ''; url = ''; movies: any; movie: any; constructor(private route: ActivatedRoute, private http: HttpClient) {} ngOnInit(): void { this.type = this.route.snapshot.params['type']; this.id = this.route.snapshot.params['id']; if (this.type === 'Trending') { this.url = 'http://localhost:4200/assets/data/trending-movies.json'; } else if (this.type === 'Theatres') { this.url = 'http://localhost:4200/assets/data/theatre-movies.json'; } else if (this.type === 'Popular') { this.url = 'http://localhost:4200/assets/data/popular-movies.json'; } this.getMovie(); } getMovie() { this.http.get(this.url).subscribe((movies) => { this.movies = movies; let index = this.movies.findIndex( (movie: { id: string }) => movie.id == this.id ); console.log(index); if (index > -1) { this.movie = this.movies[index]; } }); } }
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Aquí está la documentación en MDN .

El método findIndex() devuelve el índice del primer elemento de una matriz que satisface la función de prueba proporcionada. Si ningún elemento satisface la función de prueba, se devuelve -1.

Además, cuando trabaje con mecanografiado, es posible que desee escribir sus miembros, en lugar de escribir todo como cualquiera.

about 4 years ago · Juan Pablo Isaza Report

0

Devuelve -1 porque no hay ningún elemento que satisfaga la función de prueba

about 4 years ago · Juan Pablo Isaza Report

0

Intente verificar sus términos de búsqueda, porque como otros han notado, -1 no significa que la matriz no esté vacía, sino que no surgieron resultados con su término de búsqueda.

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!