Help us understand the problem. What is going on with this article?

Javascript -dotinstall object

forEach

{
  const scores = [80,90,40,70];
  scores.forEach((score,index)=>{
  console.log(`Score index:${index}: ${score}`);
  })
}
Score index:0: 80
Score index:1: 90
Score index:2: 40
Score index:3: 70

map

{
  const prices = [100,200,300];
  const updatePrices = prices.map((price)=>{
    return price + 20;
  });
  console.log(updatePrices);
}

配列に、何らかの処理を加えたい場合

(3) [120, 220, 320]

省略記法
・引数が一つの場合、(引数)の()を省略できる。
・returnのみ一行の場合は、return{}も省略できる。

{
  const prices = [100,200,300];
  const updatePrices = prices.map(price =>  price + 20);
  console.log(updatePrices);
}

filter

{
  const numbers = [1,4,7,8,10];
  const evenNumbers = numbers.filter(number =>{
    if(number % 2 ===0){
      return true;
    }else{
      return false;
    }
  });
  console.log(evenNumbers);
}
(3) [4, 8, 10]

省略形

{
  const numbers = [1,4,7,8,10];
  const evenNumbers = numbers.filter(number => number % 2 === 0);
  console.log(evenNumbers);
}
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした