//Revision Lecture 5: 29 Sep 2022
//Topic 4: //* JS array & methods of array *//
//methods of array 8 to 13:
// 0 1 2 3
let batsmen = ['sachin', 'sehwag', 'dravid', 'kohli']
// 8) forEach(): do modification for each element & give output modified elements
batsmen.forEach(function(el,index,arr){
console.log('hi ' + el)
})
// 9) find(): finds the asked element & returns that element
// 0 1 2 3 4 5
let numbers2 = [10,20,30,40,50,60]
let z1 = numbers2.find(function(el,index,arr){
return el > 40
})
console.log(z1)
let z2 = numbers2.find(function(el,index,arr){
return el < 30
})
console.log(z2)
// 10) findIndex(): finds the index of asked element & returns index of that element
let z3 = numbers2.findIndex(function(el){
return el > 10
})
console.log(z3)
let z4 = numbers2.findIndex(function(el){
return el > 40
})
console.log(z4)
// 11) some(): finds the asked element & return boolean value
let numbers3 = [2,4,6,8,10,12]
let z5 = numbers3.some(function(el){
return el > 4
})
console.log(z5)
let z6 = numbers3.some(function(el){
return el < 2
})
console.log(z6)
// 12) every(): finds the asked element & return boolean value
let numbers4 = [4,8,12,16,20,24]
let z7 = numbers4.every(function(el){
return el > 2
})
console.log(z7)
let z8 = numbers4.every(function(el){
return el > 10
})
console.log(z8)
// 13) filter(): filters elements of array by given condition & returns that elements in array
let numbers5 = [100,110,120,130,140,150,160]
let z9 = numbers5.filter(function(el){
return el > 120
})
console.log(z9)
let z10 = numbers5.filter(function(el){
return el < 130
})
console.log(z10)
//--------------------------
let names1 = ['ashish', 'rohit', 'vijay']
let z11 = names1.some(function(el){
return el == 'rohit'
})
console.log(z11)
let letters = ['a', 'b', 'c', 'a', 'b', 'v', 'f']
let z12 = letters.some(function(el){
return el == 'b'
})
console.log(z12)
let z13 = letters.some(function(el){
return el == 'j'
})
console.log(z13)
टिप्पण्या
टिप्पणी पोस्ट करा
आपल्या प्रतिक्रियेबद्दल धन्यवाद ! आम्ही लवकरात लवकर प्रतिक्रियेला उत्तर देण्याचा प्रयत्न करू