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

159
Vistas
accessing multiple values of array and returning them concatenated or as string
const arr = ['a','c','o','l','s','t','r','i','n','g'];

let str = arr[1,2,2,3];

//returns l

What can i do to efficiently return "cool" which is what i want?

technically I'm doing this with all of the special characters as a way to reference them in string functions cause my code kept breaking otherwise.I found this fast, easy, and efficient;

The only reasonable solution I can think of is to capitalize the array and create a function with the lowered case and have that return a concatenated version. Am hoping for a better suggestion;

---update i just did this:

function Spc(...theArgs) {
   let str = ""
   theArgs.forEach(function(element){ str += spc[element]; });
   return str;
}

 findbar.value = Spc(0,10,12)+".*"+Spc(10,12,1); 
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You need to take the indices and map the characters. Then join the array to a string.

const
    array = ['a', 'c', 'o', 'l', 's', 't', 'r', 'i', 'n', 'g'],
    indices = [1, 2, 2, 3],
    string = indices.map(i => array[i]).join('');

console.log(string);

about 4 years ago · Juan Pablo Isaza Denunciar

0

If you have an array of the indexes of the characters in 'arr', you can create a string as following:

const arr = ['a','c','o','l','s','t','r','i','n','g'];
const indexes = [1,2,2,3]

const concatenated = indexes.map(el => arr[el]); // result: ['c', 'o', 'o', 'l']
const string = concatenated.join(''); // result 'cool'
about 4 years ago · Juan Pablo Isaza Denunciar

0

Well since you prefer hard code here is what you can do to generate the string "cool". We simply create a new array of hard coded index values that generates the cool array and simply join them together!

 const arr = ['a','c','o','l','s','t','r','i','n','g'];
    
    let newArr = [arr[1],arr[2],arr[2],arr[3]];

newArr will be [c,o,o,l]

    let string = newArr.join("");

string will be join with no spaces returning "cool"

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