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

261
Vistas
javascript map, grab first index with a certain element

As you can see from my snack expo example here, I am grabbing the first index and last index of my array successfully. I am doing this so I can add a borderRadius to the top and bottom of my view. I would eventually like to have a section for online users as well as a section for offline users.

I want to be able to grab the index of the first online user in the array regardless of its position in the array overall. So if the first three indexes have the status of offline, and the fourth index is online, I want to be able to grab that fourth index because it is the first time an online status appears.

For further clarification, if you look at my example, if the last index of the entire array had the status of online, the borderRadius would not be set. If the first index of the array did not have the status of online, the borderRadius would not be set.

grab first index in entire array regardless of status -> I need this to be the first online index, not the first index in entire array

else if(i == 0){
        return ()

grab last index in entire array -> I need this to be the last index with the online status, not the last index in the entire array

if (i + 1 === List.length) {
        return ()
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can compute the first and last indexes before iterating on your users list( see https://snack.expo.dev/83rFQLCrF )

const lastIndex = List.map(e => e.status).lastIndexOf('online');
const firstIndex = List.map(e => e.status).indexOf('online');

const renderList = (props) => {
    return List.map((item, i) => {
      /* grabs last index, I need to grab the last index with status online */
      if (i  === lastIndex) {
       // TO DO
      } 
      /* grabs first index, I need to grab the first index with status online */
      else if(i == firstIndex ){
       // TO DO
      }
      else{
         // TO DO
      }

    });
  };
about 4 years ago · Juan Pablo Isaza Denunciar
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