Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const carSales = [
- { make: 'Maruti', model: 'Dzire', sales: 20610 },
- { make: 'Maruti', model: 'Baleno', sales: 14532 },
- { make: 'Hyundai', model: 'i10 Grand', sales: 14417 },
- { make: 'Maruti', model: 'Swift', sales: 12057 },
- { make: 'Hyundai', model: 'Elite i20', sales: 11012 },
- { make: 'Hyundai', model: 'Creta', sales: 9248 }
- ];
- //array with just the names of all the car model.
- let carModels = [];
- for (let i = 0; i < carSales.length; i++) {
- carModels.push(carSales[i].model);
- }
- console.log(carModels);
- //array of car made by Maruti.
- let marutiCarModels = [];
- for (let i = 0; i < carSales.length; i++) {
- if(carSales[i].make == 'Maruti')
- marutiCarModels.push(carSales[i]);
- }
- console.log(JSON.stringify(marutiCarModels));
- //Total car sales
- let totalCarSales = 0;
- for (let i = 0; i < carSales.length; i++) {
- totalCarSales = totalCarSales + carSales[i].sales;
- }
- console.log(totalCarSales);
Add Comment
Please, Sign In to add comment