Removing the Element at a Certain Index in a String: removeAt() Function

Preferences - Do not show ads

The removeAt() function helps us remove an element at a certain index in a string. Its syntax is:


String.removeAt(string, element_index, delimiter);


If the function call succeeds, the removeAt() function returns a string that is the result of removing the element at the position element_index from string. The delimiting character associated with that element is removed at the same time (if there exists one). string is not modified during the process.

If element_index is out of range, removeAt() will use the nearest valid index instead. For example, if element_index is -2, removeAt() will remove the element at index 0.

If delimiter is an empty string or an error occurs, an invalid value is returned.

Below are some WMLScript examples that can help you understand the usage of removeAt() better:


var new_str = String.removeAt("WAP, WML Tutorial, WMLScript Tutorial", 0, ",");

After executing the above script, the new_str variable has the string value " WML Tutorial, WMLScript Tutorial". Notice that the comma (the delimiter) associated with the first element is also removed.


var new_str = String.removeAt("WAP, WML Tutorial, WMLScript Tutorial", 1, ",");

After executing the above script, the new_str variable has the string value "WAP, WMLScript Tutorial".


var new_str = String.removeAt("WAP, WML Tutorial, WMLScript Tutorial", 2, ",");

After executing the above script, the new_str variable has the string value "WAP, WML Tutorial".


var new_str = String.removeAt("WAP, WML Tutorial, WMLScript Tutorial", 10, ",");

After executing the above script, the new_str variable has the string value "WAP, WML Tutorial".


Previous Page Page 49 of 71 Next Page

Contents at a Glance
Print this Web Page | | Back to Top

Feedback Form (Expand)

What do you think about this web page?






WMLScript Tutorial Table of Contents WMLScript Tutorial Contents at a Glance Preferences - Change Color Scheme Preferences - Do Not Show Ads Previous Page Next Page