Avatar of Al4ddin2
Al4ddin2

asked on 

.shift() equivalent on a text string

I am looking to loop through a string, focusing on each character at a time.

This is what I want to do, like it is an array:
var cleanText = "this is my string of characters I want to iterate through";
while(cleanText.length){
var currentChar = cleanText.shift();
// do some more stuff
}

Open in new window


so that it concentrates only on that specific character and removes it as it goes.
What alternative can use for this example as it is not an array?
JavaScript

Avatar of undefined
Last Comment
Gary
Avatar of Gary
Gary
Flag of Ireland image

var cleanText = "this is my string of characters I want to iterate through";

arrText = cleanText.split('')

var arrayLength = arrText.length;
for (var i = 0; i < arrayLength; i++) {
    var currentChar = arrText[i];
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Alexandre Simões
Alexandre Simões
Flag of Switzerland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Gary
Gary
Flag of Ireland image

Good point.
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo