TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

JavaScript Set forEach() Method

JavaScript Set forEach() Method with example, clear() method, javascript set methods, delete() method, entries() method, foreach() method, has() method, values() method etc.

<< Back to JAVASCRIPT

JavaScript Set forEach() method

The JavaScript Set forEach() method executes the specified function once for each value in the Set object. It maintains an insertion order.

Unlike Map, the Set object doesn't use key externally. To keep the values unique it uses the key internally. Thus, Set considers the value of element as a key.

Syntax

The forEach() method is represented by the following syntax:

setObj.forEach(function callback(value1, value2, Set) { 
    //your iterator
}[, thisArg])

Parameter

callback - It represents the function to execute.

value1, value2 - The value1 represents the key of the element whereas value2 represents the value. Both arguments contains the same value.

set - It represents the current Set object.

thisArg - It represents the value that treats as this when executing callback.

JavaScript Set forEach() method example

Let's see a simple example of forEach() method

<script>
var set = new Set(["jQuery","AngularJS","Bootstrap"]);
document.writeln("Fetching values :"+"<br>");
set.forEach(function display(value1,value2,set) 
{
document.writeln('key[' + value1 + '] = ' + value2+"<br>");
})
</script>
Test it Now

Output:

Fetching values :
key[jQuery] = jQuery
key[AngularJS] = AngularJS
key[Bootstrap] = Bootstrap





Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf