how to extract a single letter of string from array in javascript? eg["WORK"] OUTPUT SHOULD BE w,o,r,k on console | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

how to extract a single letter of string from array in javascript? eg["WORK"] OUTPUT SHOULD BE w,o,r,k on console

Plss solve it🙏

15th Jul 2023, 3:24 PM
Poker
Poker - avatar
5 Réponses
+ 4
You can use - the toLowerCase function to make all letters lowercase - the split function to create an array of characters from a string - the join function to combine the letters to a new string with a comma separator - console.log function to write the output It would be much easier to give you appropriate advice, if you show some attempt first. There are many possible ways to solve this task. Some of them are more advanced, and difficult to understand for beginners.
15th Jul 2023, 3:50 PM
Tibor Santa
Tibor Santa - avatar
+ 2
Poker Could you please be a bit more clear on the input and output. What is the input array you are passing? And what are you expecting as the output?
15th Jul 2023, 3:30 PM
Manoj Kumar S
+ 1
Nice one Bob_Li..
17th Jul 2023, 2:57 PM
Manoj Kumar S
0
const arr = ["WORK"]; for(let i=0; i<arr[0].length; i++){ process.stdout.write(arr[0][i].toString().toLowerCase()); if(i==arr[0].length-1){ break; } process.stdout.write(",") } Poker above is your code. Also, I've not been exposed to javascript much, so this one may need a lot of optimisation. But it gives your output from the input you give. Disclaimer: When I searched for javascript in code bits, I saw node.js and assumed that is JavaScript. As, I have not used JS before, I may be wrong. Please point out to me in such a case.
16th Jul 2023, 2:31 AM
Manoj Kumar S
0
this? let s1 = ["WORK"]; s2=[]; for(let s of s1[0].toLowerCase()) s2.push(s); console.log(s2);
17th Jul 2023, 11:59 AM
Bob_Li
Bob_Li - avatar