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đ
5 Answers
+ 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.
+ 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?
+ 1
Nice one Bob_Li..
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.
0
this?
let s1 = ["WORK"];
s2=[];
for(let s of s1[0].toLowerCase()) s2.push(s);
console.log(s2);