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

160
Views
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 answers
Answer question

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 Report

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 Report

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 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!