SlideShare a Scribd company logo
1 of 24
JAVASCRIPT-ARRAY
JavaScript - ARRAY
• When we use var, let we can stored only one
value at a time.
– var friend1 = ‘john’;
– var friend2 = ‘smith’;
– var friend3 = ‘peter’;
• When we feel like storing multiple values in one
variable then instead of var or let, we will use an
Array.
JavaScript - ARRAY
• var Names= [‘John’,’Smith’,’Peter’,’David’];
• First Element of an array known as Lower
Index/ Lower Boundary.
• Last Element of an array known as Upper
Index/ Upper Boundary.
JavaScript - ARRAY
What we will do
• Traversal of an Array
• How to insert, Add, Replace and Delete
Elements in Array(CRUD)
• Map(), Reduce(), filter()
Traversal in array
• if we want to get the single data at a time.
arrayVarName[indexNumber]
• Traverse the Last Element of an Array
arrayVarName[arrayVarName.length-1]
Loops to Traverse Array
• For loop
• For in loop
• For of loop
• forEach
Perform CRUD on Array
• Push()
– The push() method adds one or more elements to the
end of an array and returns the new length of the
array.
• Unshift()
– The unshift() method adds one or more elements to
the beginning of an array and returns the new length
of the array
Perform CRUD on Array
• Pop()
– The pop() method removes the last element from an
array and returns that element. This method changes
the length of the array
• Shift()
– The shift() method removes the first element from an
array and returns that removed element. This method
changes the length of the array.
Perform CRUD on Array
• Splice()
– The splice() method of Array changes the contents
of an array by removing or replacing existing
elements and/or adding new elements in place.
Perform CRUD on Array
• Splice()
– The General Syntax
splice(start)
splice(start, deleteCount)
splice(start, deleteCount, item0)
splice(start, deleteCount, item0, item1)
splice(start, deleteCount, item0, item1, /* …, */ itemN)
Perform CRUD on Array
• Splice(start): Parameters
– Start: Zero-based index at which to start changing
the array
– deleteCount : An integer indicating the number of
elements in the array to remove from start
– item0, …, itemN: The elements to add to the array,
beginning from start.
Task of the Day
1. Add Dec at the end of an array?
2. What is the return value of splice method?
3. update march to March (update)?
4. Delete June from an array?
const months = ['Jan', 'march', 'April', 'June', 'July'];
Map()
• Returns a new array containing the results of
calling a function on every element in this
array.
• It return new array without mutating the
original array
Map() vs forEach()
• The returning value
• Ability to chain other methods
• Mutability
Click here to read more
Example
• Find the square root of each element in an
array?
let arr = [25, 36, 49, 64, 81];
• Multiply each element by 2 and return only
those elements which are greater than 10?
let arr = [2, 3, 4, 6, 8];
Filter()
• The filter() method creates a new array with
all elements that pass the test implemented
by the provided function.
• It returns a new array containing only the
elements for which the function returns true
Example
• In the following array return only those
elements which are greater than 5?
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
Map() vs filter()
• map() is used when you want to transform each
element of an array and create a new array with the
transformed values.
• filter() is used when you want to create a new array
that contains only the elements that meet a certain
condition.
• Keep in mind that both methods do not modify the
original array; they create new arrays based on the
transformation or filtering criteria.
Reduce()
• The reduce() method executes a reducer
function (that you provide) on each element
of the array, resulting in single output value.
array.reduce(function(accumulator,currentValue,currentIndex,array)
{
// Your reducer logic here
}, initialValue);
Task: Data Processing with Map,
Filter, and Reduce
• You have an array of objects representing
different products. Each object contains
information about the product's name, price,
and quantity. Your task is to perform various
operations on this data using the map(),
filter(), and reduce() methods.
Array of an Object
const products = [
{ name: 'Laptop', price: 1000, quantity: 5 },
{ name: 'Phone', price: 600, quantity: 10 },
{ name: 'Tablet', price: 300, quantity: 7 },
{ name: 'Headphones', price: 150, quantity: 20 },
{ name: 'Monitor', price: 300, quantity: 3 }
];
Array of an Object
• Task 1: Use map() to create an array of product
names.
• Task 2: Use filter() to get products with a price
greater than $200
• Task 3: Use reduce() to calculate the total value
of all products
• Task 4 : Return only Names of the product with
price greater than $200.
THANKS

More Related Content

Similar to javascript-Array.ppsx

Similar to javascript-Array.ppsx (20)

Collection and framework
Collection and frameworkCollection and framework
Collection and framework
 
Array properties
Array propertiesArray properties
Array properties
 
Arrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | EdurekaArrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | Edureka
 
arrays in c# including Classes handling arrays
arrays in c#  including Classes handling arraysarrays in c#  including Classes handling arrays
arrays in c# including Classes handling arrays
 
22.ppt
22.ppt22.ppt
22.ppt
 
Underscore.js
Underscore.jsUnderscore.js
Underscore.js
 
Java script advance-auroskills (2)
Java script advance-auroskills (2)Java script advance-auroskills (2)
Java script advance-auroskills (2)
 
Array
ArrayArray
Array
 
Arrays.pptx
Arrays.pptxArrays.pptx
Arrays.pptx
 
4. Array.pptx
4. Array.pptx4. Array.pptx
4. Array.pptx
 
0-Slot18-19-20-ContiguousStorage.pdf
0-Slot18-19-20-ContiguousStorage.pdf0-Slot18-19-20-ContiguousStorage.pdf
0-Slot18-19-20-ContiguousStorage.pdf
 
Unit 2 dsa LINEAR DATA STRUCTURE
Unit 2 dsa LINEAR DATA STRUCTUREUnit 2 dsa LINEAR DATA STRUCTURE
Unit 2 dsa LINEAR DATA STRUCTURE
 
DS Unit 1.pptx
DS Unit 1.pptxDS Unit 1.pptx
DS Unit 1.pptx
 
ACP-arrays.pptx
ACP-arrays.pptxACP-arrays.pptx
ACP-arrays.pptx
 
What are arrays in java script
What are arrays in java scriptWhat are arrays in java script
What are arrays in java script
 
ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
ARRAYS.pptx
 
NUMPY-2.pptx
NUMPY-2.pptxNUMPY-2.pptx
NUMPY-2.pptx
 
Operators in mule dataweave
Operators in mule dataweaveOperators in mule dataweave
Operators in mule dataweave
 
Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1
 
F# array searching
F#  array searchingF#  array searching
F# array searching
 

Recently uploaded

Unveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystUnveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystSamantha Rae Coolbeth
 
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls DubaiDubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls Dubaihf8803863
 
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...Suhani Kapoor
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...Suhani Kapoor
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Call Girls In Mahipalpur O9654467111 Escorts Service
Call Girls In Mahipalpur O9654467111  Escorts ServiceCall Girls In Mahipalpur O9654467111  Escorts Service
Call Girls In Mahipalpur O9654467111 Escorts ServiceSapana Sha
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptxthyngster
 
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiLow Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiSuhani Kapoor
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSAishani27
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxStephen266013
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingNeil Barnes
 
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Sapana Sha
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...Florian Roscheck
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...dajasot375
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改atducpo
 
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...shivangimorya083
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998YohFuh
 

Recently uploaded (20)

Unveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystUnveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data Analyst
 
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls DubaiDubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
 
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
 
E-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptxE-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptx
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls In Mahipalpur O9654467111 Escorts Service
Call Girls In Mahipalpur O9654467111  Escorts ServiceCall Girls In Mahipalpur O9654467111  Escorts Service
Call Girls In Mahipalpur O9654467111 Escorts Service
 
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in  KishangarhDelhi 99530 vip 56974 Genuine Escort Service Call Girls in  Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
 
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiLow Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICS
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docx
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data Storytelling
 
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
 
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998
 

javascript-Array.ppsx

  • 2. JavaScript - ARRAY • When we use var, let we can stored only one value at a time. – var friend1 = ‘john’; – var friend2 = ‘smith’; – var friend3 = ‘peter’; • When we feel like storing multiple values in one variable then instead of var or let, we will use an Array.
  • 3. JavaScript - ARRAY • var Names= [‘John’,’Smith’,’Peter’,’David’]; • First Element of an array known as Lower Index/ Lower Boundary. • Last Element of an array known as Upper Index/ Upper Boundary.
  • 5. What we will do • Traversal of an Array • How to insert, Add, Replace and Delete Elements in Array(CRUD) • Map(), Reduce(), filter()
  • 6. Traversal in array • if we want to get the single data at a time. arrayVarName[indexNumber] • Traverse the Last Element of an Array arrayVarName[arrayVarName.length-1]
  • 7. Loops to Traverse Array • For loop • For in loop • For of loop • forEach
  • 8. Perform CRUD on Array • Push() – The push() method adds one or more elements to the end of an array and returns the new length of the array. • Unshift() – The unshift() method adds one or more elements to the beginning of an array and returns the new length of the array
  • 9. Perform CRUD on Array • Pop() – The pop() method removes the last element from an array and returns that element. This method changes the length of the array • Shift() – The shift() method removes the first element from an array and returns that removed element. This method changes the length of the array.
  • 10. Perform CRUD on Array • Splice() – The splice() method of Array changes the contents of an array by removing or replacing existing elements and/or adding new elements in place.
  • 11. Perform CRUD on Array • Splice() – The General Syntax splice(start) splice(start, deleteCount) splice(start, deleteCount, item0) splice(start, deleteCount, item0, item1) splice(start, deleteCount, item0, item1, /* …, */ itemN)
  • 12. Perform CRUD on Array • Splice(start): Parameters – Start: Zero-based index at which to start changing the array – deleteCount : An integer indicating the number of elements in the array to remove from start – item0, …, itemN: The elements to add to the array, beginning from start.
  • 13. Task of the Day 1. Add Dec at the end of an array? 2. What is the return value of splice method? 3. update march to March (update)? 4. Delete June from an array? const months = ['Jan', 'march', 'April', 'June', 'July'];
  • 14. Map() • Returns a new array containing the results of calling a function on every element in this array. • It return new array without mutating the original array
  • 15. Map() vs forEach() • The returning value • Ability to chain other methods • Mutability Click here to read more
  • 16. Example • Find the square root of each element in an array? let arr = [25, 36, 49, 64, 81]; • Multiply each element by 2 and return only those elements which are greater than 10? let arr = [2, 3, 4, 6, 8];
  • 17. Filter() • The filter() method creates a new array with all elements that pass the test implemented by the provided function. • It returns a new array containing only the elements for which the function returns true
  • 18. Example • In the following array return only those elements which are greater than 5? const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
  • 19. Map() vs filter() • map() is used when you want to transform each element of an array and create a new array with the transformed values. • filter() is used when you want to create a new array that contains only the elements that meet a certain condition. • Keep in mind that both methods do not modify the original array; they create new arrays based on the transformation or filtering criteria.
  • 20. Reduce() • The reduce() method executes a reducer function (that you provide) on each element of the array, resulting in single output value. array.reduce(function(accumulator,currentValue,currentIndex,array) { // Your reducer logic here }, initialValue);
  • 21. Task: Data Processing with Map, Filter, and Reduce • You have an array of objects representing different products. Each object contains information about the product's name, price, and quantity. Your task is to perform various operations on this data using the map(), filter(), and reduce() methods.
  • 22. Array of an Object const products = [ { name: 'Laptop', price: 1000, quantity: 5 }, { name: 'Phone', price: 600, quantity: 10 }, { name: 'Tablet', price: 300, quantity: 7 }, { name: 'Headphones', price: 150, quantity: 20 }, { name: 'Monitor', price: 300, quantity: 3 } ];
  • 23. Array of an Object • Task 1: Use map() to create an array of product names. • Task 2: Use filter() to get products with a price greater than $200 • Task 3: Use reduce() to calculate the total value of all products • Task 4 : Return only Names of the product with price greater than $200.