Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

165
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda