let students = [];
for (let i = 1; i <= 10; i++) {
students.push({
Id: i,
Name: "Student" + i,
Roll: "100" + i
});
}
Use of .map() :
let useMap = students.map(x=>x.Roll == 1004);
Output :
Use of .map() with .filter() :
let useMapWithFilter = students.map(x=>x.Roll == 1004 ? x : null).filter(n=>n);
Output :
Use of .find() :
let useFind = students.find(x=>x.Roll == 1004);
Output :
Use of .filter() :
let usefilter = students.filter(x => x.Roll == 1004);
Output :
N.B : .find() is faster then .filter() and .reduce()
Use of .findIndex() :
let useFindIndex = students.findIndex(x => x.Roll == 1004);
Output : 3
0 Comments