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

222
Vistas
How can i get index of 1 from Arrays of Array

Im getting an Array like this [[2,4],[7,32],[76,44],[34,22]...] up to 100, i want to get 5 Arrays out of all arrays, with the index of 1 in each of the array. am getting the index of 1 in each item in the arrays but how can i get the five different item, i want to select 3 random elements(plus the first and last one). can someone please help me out.

i want to the output to be something like this

4 44 30 77 66

Here's my code

const items = [[2,4],[7,32],[76,44],[34,22],[10,30],[34,67],[90,13],[20,14],[78,77],[9,77],[44,66]]

items.map(item => console.log(item[1]))
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Update 2.0

Take 3 random items and the first and the last item from the items array and return the index 1 from each item.

items = [[2,4],[7,32],[76,44],[34,22],[10,30],[34,67],[90,13],[20,14],[78,77],[9,77],[44,66]]


function action(arr) {
  const f = arr[0];
  const l = arr[arr.length-1]
  const a = arr.slice(1, arr.length-1)
  const t = [];

  for(i=0; i<3;i++) {  
    t.push(a[Math.floor(Math.random()*a.length)][1]);  
  }
  return [f[1], ...t, l[1]];
}


console.log(action(items))

old answer

slice() would the right approach.

const items = [[2,4],[7,32],[76,44],[34,22],[10,30],[34,67],[90,13],[20,14],[78,77],[9,77],[44,66]]

function action(arr, from, to) {
  return arr.slice(from, to)
}
console.log(action(items, 1, 6));

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