Javascript String @@iterator Method Last Updated : 09 Jan, 2023 Summarize Comments Improve Suggest changes Share 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 AbstractCollection toString() Method in Java S satyam00so Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Methods Similar Reads 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 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 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 Java Collections emptyIterator() Method with Examples The emptyIterator() method of Java Collections returns an iterator with no elements. This method is immutable. That is, we can not do any modifications after creating this method. Syntax: Iterator<data_type> object = Collections.emptyIterator(); where, data_type is the type of iterator objecto 1 min read Vector listIterator() method in Java with Examples java.util.Vector.listIterator() This method returns a list iterator over the elements of a Vector object in proper sequence. It is bidirectional, so both forward and backward traversal is possible, using next() and previous() respectively. The iterator thus returned is fail-fast. This means that str 3 min read Like