Advertisement
BojidarDosev

b

Mar 11th, 2024
628
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const artists = ['Picasso', 'Kahlo', 'Matisse', 'Utamaro'];
  2.  
  3. //Performs the specified action for each element in an array.
  4. artists.forEach(artist => {
  5.   console.log(artist + ' is one of my favorite artists.');
  6. });
  7.  
  8. const numbers = [1, 2, 3, 4, 5];
  9.  
  10. //Calls a defined callback function on each element of an array, and returns an array that contains the results.
  11. const squareNumbers = numbers.map(number => {
  12.   return number * number;
  13. });
  14.  
  15. console.log(squareNumbers);
  16.  
  17. const things = ['desk', 'chair', 5, 'backpack', 3.14, 100];
  18.  
  19. const onlyNumbers = things.filter(thing => {
  20.   return typeof thing === 'number';
  21. });
  22.  
  23. console.log(onlyNumbers);
  24.  
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement