It just all of a suddenly crossed my mind we all know using regular for
loop and push()
method to convert string characters into an array
let myStr = "Perseverance";
let emptyArr = [];
for (let i = 0; i < myStr.length; i++) {
emptyArr.push(myStr[i]);
}
console.log(emptyArr);
then I decided to convert a whole string into a single element of an array just using push()
...worked
let myStr = "Perseverance powers";
let emptyArr = [];
for (let i = 0; i < myStr.split().length; i++) {
emptyArr.push(myStr);
}
console.log(emptyArr);
Now here when I want to separate each word into a single element of an array just using push()
I can't...
Here is my question: How can I convert each word of the string into a single element of an array using only push()
and for
loop
P.S. A lot ways exist yet it was just a thought came to my mind 'what if' Thanks