Saturday, April 11, 2020

find() Array Method

Document

find() Array Method

find()-Array method

find() method ကို လိုချင်တဲ့ value ကို array ကနေ ပထမဆုံးရှာတွေ့တဲ့ value ကိုလိုချင်တဲ့အခါသုံးပါတယ်။ ဥပမာ array ကနေ 30 ထက်ကြီးတဲ့ ပထဆုံး value ကိုလိုချင်တယ်ဆိုပါစို့ ။ Const prices = [20,10,50,40,60]; ဒီ array ထဲကနေ 30 ထက်ကြီးတဲ့ value ကိုရှာရင် ပထဆုံး 30 ထက်ကြီးတဲ့ value ဖြစ်တဲ့ 50 ကိုရပါလိမ့်မယ်။
Example 

//example array
const prices = [20,30,40,35,60];

//Here is usage of find() method 
//to find the first element 

const answer = prices.find(price=>price>30);
console.log(answer);
//output -> 40

    
parameter တစ်ခုထဲဆို () မလိုပါဘူး။ => function သုံးတဲ့ အတွက် return keyword လည်းမလိုပါဘူး။

No comments:

Post a Comment