Projects > Array JS
June 04, 2021 | Learning JS
const inventors = [
{ first: 'Albert', last: 'Einstein', year: 1879, passed: 1955 },
{ first: 'Isaac', last: 'Newton', year: 1643, passed: 1727 },
{ first: 'Galileo', last: 'Galilei', year: 1564, passed: 1642 },
{ first: 'Marie', last: 'Curie', year: 1867, passed: 1934 },
{ first: 'Johannes', last: 'Kepler', year: 1571, passed: 1630 },
{ first: 'Nicolaus', last: 'Copernicus', year: 1473, passed: 1543 },
{ first: 'Max', last: 'Planck', year: 1858, passed: 1947 },
{ first: 'Katherine', last: 'Blodgett', year: 1898, passed: 1979 },
{ first: 'Ada', last: 'Lovelace', year: 1815, passed: 1852 },
{ first: 'Sarah E.', last: 'Goode', year: 1855, passed: 1905 },
{ first: 'Lise', last: 'Meitner', year: 1878, passed: 1968 },
{ first: 'Hanna', last: 'Hammarström', year: 1829, passed: 1909 }
];
const filteredInvestors = investors.filter(investor => investor.year >= 1500 && investor.year <= 1600);
// This will return investor with year that is less than 16 and greater than 15
const oneArray = investors.map(investor => `${investor.first} ${investor.last}`);
// Return full names of array
const ordered = investors.sort((firstPerson, secondPerson) => firstPerson.year > secondPerson.year ? 1 : -1);
// Arranging in order whose year is greater, this starts from least to greatest
Basically, it is like finding the total from a list of objects
const totalYears = investors.reduce((total, investor) => {return total += investor.passed - investor.year}, 0); // 0 here is the default value for total
const data = ['car', 'car', 'duck', 'dog']; const countWord = data.reduce((obj, item) => { if (!obj[item]) obj[item] = 0; obj[item]++; return obj; }, {})
students.some(student => student.born > 2010); // return true
students.every(student => (student.dies - student.born) > 20);
students.find(student => student.first_name === 'Halsey');
// This return an object that contain Halsey as first name
// Check in console.log when click
students.findIndex(student => student.email.includes("doumic"));
// Return index number if exists
There are 10 records of the students, please check in the console