SlideShare a Scribd company logo
const myArr = [1, 2, 3];
console.log(myArr[0]);
// Output: 1
const mySet
= new Set([1, 2, 3]);
console.log(mySet[0]);
// undefined
const arr1 = [1,2,3,3];
// Initializes an array with
4 items
const set1 = new Set(
[1, 2, 3, 3]
); // Initializes with 3
items
// method 1
var arr1 = [ ];
// method 2
var arr2 = new array();
// Initializes an empty set
const set1 = new Set();
// Initialize with value
const set2 = new Set([1, 2,
3]);
Initialize a set
Duplicate values are not allowed
Items can be accessed using index Items cannot be accessed using index
Initialize an array
Duplicate values are allowed
VSARRAY SET
[🍎, 🍎, 🍐, 🍐, 🍊] [🍎,🍎, 🍐, 🍐, 🍊] [🍎, 🍎, 🍐, 🍐, 🍊] [🍎, 🍐, 🍊]
By combining features of array and a set in
javascript, we get more powerful code.
Example
Easy shortcut to remove duplicates from an array
Brought to you by Ideas2IT
TRICKS TO REMOVE
DUPLICATES FROM ARRAY
// array with duplicates
let array1 = [1,1,2,2,3,3,4,4];
// create a Set with array
let array2 = Array.from(new Set(array1));
console.log(array2); // [ 1, 2, 3, 4 ]

More Related Content

What's hot (20)

Applications of stack
Applications of stack
eShikshak
 
Shell sort
Shell sort
Rajendran
 
Data structure - Graph
Data structure - Graph
Madhu Bala
 
Binary Search
Binary Search
kunj desai
 
Heap sort
Heap sort
Ayesha Tahir
 
Asymptotic Notations
Asymptotic Notations
Rishabh Soni
 
PL/SQL - CURSORS
PL/SQL - CURSORS
IshaRana14
 
Sorting Algorithms
Sorting Algorithms
Pranay Neema
 
Tuples in Python
Tuples in Python
DPS Ranipur Haridwar UK
 
Python-DataAbstarction.pptx
Python-DataAbstarction.pptx
Karudaiyar Ganapathy
 
B+ tree.pptx
B+ tree.pptx
Maitri Shah
 
DAA Unit 1.pdf
DAA Unit 1.pdf
Nirmalavenkatachalam
 
Intermediate code generator
Intermediate code generator
sanchi29
 
Optimization of basic blocks
Optimization of basic blocks
ishwarya516
 
Java Exception handling
Java Exception handling
kamal kotecha
 
Python-Inheritance.pptx
Python-Inheritance.pptx
Karudaiyar Ganapathy
 
Queues
Queues
Lovely Professional University
 
Forms in AngularJS
Forms in AngularJS
Eyal Vardi
 
Heap sort
Heap sort
International Islamic University
 
Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)
Self-Employed
 

Similar to Array vs set in JavaScript (10)

Data structures Lecture 5
Data structures Lecture 5
AzharIqbal710687
 
Arrays in Java with example and types of array.pptx
Arrays in Java with example and types of array.pptx
ashwinibhosale27
 
javaArrays.pptx
javaArrays.pptx
AshishNayyar11
 
Groovy collection api
Groovy collection api
trygvea
 
Chap 6 c++
Chap 6 c++
Venkateswarlu Vuggam
 
Java arrays
Java arrays
BHUVIJAYAVELU
 
Chap 6 c++
Chap 6 c++
Venkateswarlu Vuggam
 
Python programming -Tuple and Set Data type
Python programming -Tuple and Set Data type
Megha V
 
SP-First-Lecture.ppt
SP-First-Lecture.ppt
FareedIhsas
 
Ken20150417
Ken20150417
LearningTech
 
Arrays in Java with example and types of array.pptx
Arrays in Java with example and types of array.pptx
ashwinibhosale27
 
Groovy collection api
Groovy collection api
trygvea
 
Python programming -Tuple and Set Data type
Python programming -Tuple and Set Data type
Megha V
 
SP-First-Lecture.ppt
SP-First-Lecture.ppt
FareedIhsas
 
Ad

More from Ideas2IT Technologies (20)

Version comaparison in JavaScript
Version comaparison in JavaScript
Ideas2IT Technologies
 
Currying in JavaScript
Currying in JavaScript
Ideas2IT Technologies
 
JS Testing Frameworks
JS Testing Frameworks
Ideas2IT Technologies
 
Cool usage of Encoding and Decoding a URI in Javascript
Cool usage of Encoding and Decoding a URI in Javascript
Ideas2IT Technologies
 
Iterables and Iterators in JavaScript
Iterables and Iterators in JavaScript
Ideas2IT Technologies
 
String comparison in javascript
String comparison in javascript
Ideas2IT Technologies
 
JavaScript symbols
JavaScript symbols
Ideas2IT Technologies
 
Json.parse() in JavaScript
Json.parse() in JavaScript
Ideas2IT Technologies
 
Bubble sort in Java Script
Bubble sort in Java Script
Ideas2IT Technologies
 
Performance analysis in merging arrays - JavaScript
Performance analysis in merging arrays - JavaScript
Ideas2IT Technologies
 
Nullish coalescing in JavaScript
Nullish coalescing in JavaScript
Ideas2IT Technologies
 
Conditionally add keys in JavaScript
Conditionally add keys in JavaScript
Ideas2IT Technologies
 
What is Big O in JavaScript - Part-1
What is Big O in JavaScript - Part-1
Ideas2IT Technologies
 
Variable hoisting in JavaScript
Variable hoisting in JavaScript
Ideas2IT Technologies
 
Formidable ES6 spread operator in JavaScript
Formidable ES6 spread operator in JavaScript
Ideas2IT Technologies
 
Logging in JavaScript - Part-5
Logging in JavaScript - Part-5
Ideas2IT Technologies
 
Logging in JavaScript - Part-4
Logging in JavaScript - Part-4
Ideas2IT Technologies
 
Logging in JavaScript - Part-3
Logging in JavaScript - Part-3
Ideas2IT Technologies
 
Logging in JavaScript - part-2
Logging in JavaScript - part-2
Ideas2IT Technologies
 
Logging in JavaScript - part-1
Logging in JavaScript - part-1
Ideas2IT Technologies
 
Cool usage of Encoding and Decoding a URI in Javascript
Cool usage of Encoding and Decoding a URI in Javascript
Ideas2IT Technologies
 
Iterables and Iterators in JavaScript
Iterables and Iterators in JavaScript
Ideas2IT Technologies
 
Performance analysis in merging arrays - JavaScript
Performance analysis in merging arrays - JavaScript
Ideas2IT Technologies
 
Conditionally add keys in JavaScript
Conditionally add keys in JavaScript
Ideas2IT Technologies
 
What is Big O in JavaScript - Part-1
What is Big O in JavaScript - Part-1
Ideas2IT Technologies
 
Formidable ES6 spread operator in JavaScript
Formidable ES6 spread operator in JavaScript
Ideas2IT Technologies
 
Ad

Recently uploaded (20)

Transmission Media. (Computer Networks)
Transmission Media. (Computer Networks)
S Pranav (Deepu)
 
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
Maharshi Mallela
 
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2
 
Microsoft Business-230T01A-ENU-PowerPoint_01.pptx
Microsoft Business-230T01A-ENU-PowerPoint_01.pptx
soulamaabdoulaye128
 
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Natan Silnitsky
 
Zoneranker’s Digital marketing solutions
Zoneranker’s Digital marketing solutions
reenashriee
 
Reimagining Software Development and DevOps with Agentic AI
Reimagining Software Development and DevOps with Agentic AI
Maxim Salnikov
 
Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4
Gaurav Sharma
 
Open Source Software Development Methods
Open Source Software Development Methods
VICTOR MAESTRE RAMIREZ
 
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Alluxio, Inc.
 
Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
What is data visualization and how data visualization tool can help.pdf
What is data visualization and how data visualization tool can help.pdf
Varsha Nayak
 
Step by step guide to install Flutter and Dart
Step by step guide to install Flutter and Dart
S Pranav (Deepu)
 
Artificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across Industries
SandeepKS52
 
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
BradBedford3
 
AI-Powered Compliance Solutions for Global Regulations | Certivo
AI-Powered Compliance Solutions for Global Regulations | Certivo
certivoai
 
IBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - Introduction
Gaurav Sharma
 
wAIred_RabobankIgniteSession_12062025.pptx
wAIred_RabobankIgniteSession_12062025.pptx
SimonedeGijt
 
How to Choose the Right Web Development Agency.pdf
How to Choose the Right Web Development Agency.pdf
Creative Fosters
 
SAP PM Module Level-IV Training Complete.ppt
SAP PM Module Level-IV Training Complete.ppt
MuhammadShaheryar36
 
Transmission Media. (Computer Networks)
Transmission Media. (Computer Networks)
S Pranav (Deepu)
 
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
Maharshi Mallela
 
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2
 
Microsoft Business-230T01A-ENU-PowerPoint_01.pptx
Microsoft Business-230T01A-ENU-PowerPoint_01.pptx
soulamaabdoulaye128
 
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Natan Silnitsky
 
Zoneranker’s Digital marketing solutions
Zoneranker’s Digital marketing solutions
reenashriee
 
Reimagining Software Development and DevOps with Agentic AI
Reimagining Software Development and DevOps with Agentic AI
Maxim Salnikov
 
Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4
Gaurav Sharma
 
Open Source Software Development Methods
Open Source Software Development Methods
VICTOR MAESTRE RAMIREZ
 
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Alluxio, Inc.
 
Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
What is data visualization and how data visualization tool can help.pdf
What is data visualization and how data visualization tool can help.pdf
Varsha Nayak
 
Step by step guide to install Flutter and Dart
Step by step guide to install Flutter and Dart
S Pranav (Deepu)
 
Artificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across Industries
SandeepKS52
 
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
BradBedford3
 
AI-Powered Compliance Solutions for Global Regulations | Certivo
AI-Powered Compliance Solutions for Global Regulations | Certivo
certivoai
 
IBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - Introduction
Gaurav Sharma
 
wAIred_RabobankIgniteSession_12062025.pptx
wAIred_RabobankIgniteSession_12062025.pptx
SimonedeGijt
 
How to Choose the Right Web Development Agency.pdf
How to Choose the Right Web Development Agency.pdf
Creative Fosters
 
SAP PM Module Level-IV Training Complete.ppt
SAP PM Module Level-IV Training Complete.ppt
MuhammadShaheryar36
 

Array vs set in JavaScript

  • 1. const myArr = [1, 2, 3]; console.log(myArr[0]); // Output: 1 const mySet = new Set([1, 2, 3]); console.log(mySet[0]); // undefined const arr1 = [1,2,3,3]; // Initializes an array with 4 items const set1 = new Set( [1, 2, 3, 3] ); // Initializes with 3 items // method 1 var arr1 = [ ]; // method 2 var arr2 = new array(); // Initializes an empty set const set1 = new Set(); // Initialize with value const set2 = new Set([1, 2, 3]); Initialize a set Duplicate values are not allowed Items can be accessed using index Items cannot be accessed using index Initialize an array Duplicate values are allowed VSARRAY SET [🍎, 🍎, 🍐, 🍐, 🍊] [🍎,🍎, 🍐, 🍐, 🍊] [🍎, 🍎, 🍐, 🍐, 🍊] [🍎, 🍐, 🍊]
  • 2. By combining features of array and a set in javascript, we get more powerful code. Example Easy shortcut to remove duplicates from an array Brought to you by Ideas2IT TRICKS TO REMOVE DUPLICATES FROM ARRAY // array with duplicates let array1 = [1,1,2,2,3,3,4,4]; // create a Set with array let array2 = Array.from(new Set(array1)); console.log(array2); // [ 1, 2, 3, 4 ]