JS part 2:
Day 1:
filter() : filter() will always return new array. It will not modify existing array. isBiggerThanFive is the inline callback() function
var number = [0,1,2,3,4,5,6,7,8,9];
console.log(number.filter(isBiggerThanFive));
function isBiggerThanFive(n){
return n>5
}
In callback() function we can test the conditions and return to the callback()
find(): used to filter an element using Id. when the element was not found find() will return the undefined.
number.find(isBiggerThanFive);
loop():
var n = [0,1,2,3,4,5,6,7,8,9]
var filterArray=[];count = 0;
for(var i=0;i<=n.length-1;i++){
let el = a[i];
if(el>5){
filterArray.push(a[i]);
}else{ count += 1;}
}
findIndex(): we can get the element of index by using findIndex() method.
number.findIndex(4)
includes(): includes() will return true or false; true means value present in the array. number.includes(5);
There are two common functionalities that is loadData() and showData() related to web development.
loadData() can use window.fetch()
function loadData(jsonUrl, onLoadCallBack){
window.fetch(jsonUrl).then((res)=> { return res.json()}).then((data)=>{onLoadCallBack(data)});
}
Summary:
filter & search:
number.filter(): filter() => filter the data or element without changing existing array.
number.find(): find() => filter an element by using Id.
number.loop(): loop() => we can filter data or object by using loop
number.findIndex(): findIndex() => return index of value or element
number.includes(): includes(): return true if value or element are existing in the array.
Comments
Post a Comment