Javascript String @@iterator Method Last Updated : 09 Jan, 2023 Comments Improve Suggest changes Like Article Like Report String [@@iterator]( ) Method is used to make String iterable. [@@iterator]() returns an iterator object which iterates over all code points of String. String[@@iterator] is a Built-in Property of String. We can use this method by making a string iterator. We can make an iterator by calling the @@iterator property of String. In place of @@iterator, we use Symbol.iterator constant. Syntax: // Test String var str ="String"; // iterator to String var iter = str[Symbol.iterator](); We can get the iterator object with next(). It returns the object with the key value and is done. The value key holds a real iterating value string and the done key holds true or false if iteration finishes it keeps true if not then false. We can get the value of the object by str.value and done by str.done. Example 1: Below is the code that illustrates the use of the above approach. JavaScript <script> const str = 'GFG'; const iterator = str[Symbol.iterator](); let theChar = iterator.next(); for(let i = 0; i < str.length ;i++) { console.log(theChar.value , theChar.done); theChar = iterator.next(); } </script> Output : "G" false "F" false "G" false We can use the @@iterator method without assigning an iterator by using for — of loop to iterate the over-collection of data in using @@iterator method. On each iteration for — of loop call _next().value to iterate in the collection. Example 2: Below is the code that illustrates the use of the above approach. JavaScript <script> const str = 'GFG'; const iterator = str[Symbol.iterator](); let theChar = iterator; for(let i = 0; i < str.length ;i++) { console.log(theChar.next().value ); } // Using for - of loop console.log("Iterating by for-of loop :") for(let i of str) { console.log(i) } </script> Output: "G" "F" "G" Iterating by for-of loop : "G" "F" "G" Supported Browsers: Google Chrome 38 and aboveEdge 12 and aboveFirefox 36 and aboveOpera 25 and aboveSafari 9 and aboveInternet Explorer not supported We have a complete list of Javascript string methods, to check those please go through this Javascript String Complete reference article. Comment More infoAdvertise with us Next Article Javascript String @@iterator Method S satyam00so Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Methods Similar Reads Iterator Method | JavaScript Design Pattern Iterator design pattern is a behavioral design pattern that provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation. It separates the responsibility of accessing and traversing the elements from the aggregate object. This pattern is wi 4 min read JavaScript Map.prototype[@@iterator]() Method Map[@@iterator]( ) method is used to make Map iterable. Map[@@iterator]( ) method returns iterator object which iterates over all code points of Map. Map[@@iterator]( ) is built-in property of Map. We can use this method by creating Map iterator. We can make Map iterator by calling the @@iterator pr 2 min read JavaScript Symbol iterator Property It is an object of Iterables which is also a kind of generalized arrays. Iterables that make any object easier to use in a for..of the loop. We know that arrays are iterative in nature but other than that, there are also several objects which are used for the iterative purpose. Suppose if any object 2 min read AbstractCollection toString() Method in Java In Java, the toString() method is defined in the Object class and is inherited by all the Java classes. It is used to return a string representation of an object. The AbstractCollection class is a part of the Java Collections Framework, which overrides this method to provide a string representation 1 min read Vector iterator() method in Java with Examples iterator() method of Vector class that is present inside java.util package is used to return an iterator of the same elements as that of the Vector. The elements are returned in random order from what was present in the vector. Syntax: Iterator iterate_value = Vector.iterator(); Parameters: The func 2 min read TypeScript Array Symbol.iterator Method In TypeScript the Symbol.iterator function plays a role, in allowing iteration over arrays using for...of loops and other iterator-based mechanisms. This built-in function eliminates the need, for definition when working with arrays simplifying the process of accessing elements. Syntax:const iterato 3 min read ArrayList iterator() method in Java with Examples The iterator() method of ArrayList class in Java Collection Framework is used to get an iterator over the elements in this list in proper sequence. The returned iterator is fail-fast. Syntax: Iterator iterator() Parameter: This method do not accept any parameter. Return Value: This method returns an 2 min read Convert List of Characters to String in Java Given a list of characters. In this article, we will write a Java program to convert the given list to a string. Example of List-to-String ConversionInput : list = {'g', 'e', 'e', 'k', 's'} Output : "geeks" Input : list = {'a', 'b', 'c'} Output : "abc" Strings - Strings in Java are objects that are 4 min read Vector toString() method in Java with Example The java.util.Vector.toString() is an inbuilt method of Vector that is used to get a string representation of the objects of Vector in the form of a String representation of entries separated by ", ". So basically the toString() method is used to convert all the elements of Vector into String.Syntax 2 min read DelayQueue iterator() method in Java with Examples The iterator() method of DelayQueue is used to return an iterator over all the elements in the DelayQueue. These elements can be expired or unexpired.Syntax: public Iterator iterator () Parameters: This method does not accept any parameter.Returns: This method returns an iterator over elements in th 2 min read Like