Guest User

Untitled

a guest
Nov 19th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. const carSales = [
  2. { make: 'Maruti', model: 'Dzire', sales: 20610 },
  3. { make: 'Maruti', model: 'Baleno', sales: 14532 },
  4. { make: 'Hyundai', model: 'i10 Grand', sales: 14417 },
  5. { make: 'Maruti', model: 'Swift', sales: 12057 },
  6. { make: 'Hyundai', model: 'Elite i20', sales: 11012 },
  7. { make: 'Hyundai', model: 'Creta', sales: 9248 }
  8. ];
  9.  
  10. //array with just the names of all the car model.
  11. let carModels = [];
  12. for (let i = 0; i < carSales.length; i++) {
  13. carModels.push(carSales[i].model);
  14. }
  15. console.log(carModels);
  16.  
  17. //array of car made by Maruti.
  18. let marutiCarModels = [];
  19. for (let i = 0; i < carSales.length; i++) {
  20. if(carSales[i].make == 'Maruti')
  21. marutiCarModels.push(carSales[i]);
  22. }
  23. console.log(JSON.stringify(marutiCarModels));
  24.  
  25. //Total car sales
  26. let totalCarSales = 0;
  27. for (let i = 0; i < carSales.length; i++) {
  28. totalCarSales = totalCarSales + carSales[i].sales;
  29. }
  30. console.log(totalCarSales);
Add Comment
Please, Sign In to add comment