Module‌‌‌ ‌‌‌২৮ ‌‌‌এ‌‌‌ ‌‌‌আমরা‌‌‌ ‌‌‌যাকিছু‌‌‌ ‌‌‌শিখেছি‌‌‌

Module‌‌‌ ‌‌‌২৮ ‌‌‌এ‌‌‌ ‌‌‌আমরা‌‌‌ ‌‌‌যাকিছু‌‌‌ ‌‌‌শিখেছি‌‌‌

Module 28: String and Array useful methods

 

 

  • toLowerCase ও toUpperCase এর কাজ কি ?

  • toLowerCase ও toUpperCase দিয়ে প্রোডাক্ট সার্চ করে দেখাও

 

const products = [

  "samsung m20 phone", "oppo a10 phone",  "lenovo l5 ",  "corsiar m.2",  "zoetac 1650",  "samsung A30 phone",  "xiomi a3 phone", "xiomi a4 phone", ];

const searching = "PHONE";

const output = [];

for (product of products) {

   if (product.toLowerCase().indexOf(searching.toLowerCase()) !== -1){

     output.push(product);

   }

}

console.log(output);

 

 

  • আমরা চাইলে নং কাজ টা আরো একটাভাবে করতে পারি । .includesএর মাধ্যমে । .includes এর কাজ হল যেটা আমরা চাচ্ছী সেটা আছে কিনা চেক করা

 

for (product of products) {

  if (product.toLowerCase().includes(searching.toLowerCase())) {

    output.push(product);

  }

}

console.log(output);

 

 

  • startsWith ও  endsWith এর কাজ কি ?

  • .split() ও .splice() ও .substr() ও .subString()  এর কাজ কি ?

 

const a = "rashedul islam shihab";

// const word = a.split(" ");

// const word = a.split("a");//যেখানে a পাবে সেখানে ভাগ করে দিবে

// const word = a.slice(5, 8); // ৫ থেকে ৮ ইনডেক্স দেখাবে

// const word = a.substr(5, 8); // ৫ এর পর থেকে ৮ তা ইনডেক্স দেখাবে

// const word = a.substring(5, 8); //৫ থেকে ৮ এর আগ পর্যন্ত ইনডেক্স দেখাবে

console.log(word);

 

  • .concat এর কাজ কি ?

  • .join এর কাজ কি ?

 

const words = ["a", "b", "c", "d"];

const allJoin = words.join("");

console.log(allJoin);

 

  • যদি কেও ফাংশন কল করার সময় প্যারামিটার হিসেবে Array না দেয় তাহলে কিভাবে error এর সাথে দেখা করিয়ে দিতে পার ?

 

function megaFriends(friends) {

//through an error

  if (Array.isArray(friends) === false) {

    return "please give an array";}

  let mega = friends;

  for (friend of friends) {

    if (friend.length > mega.length) {

      mega = friend;}} return mega}

const friends = ["rashedul islam shihab","rashedul","islam","shihab","sabbir","rumman","taki",];

console.log(megaFriends(friends));

 

 

  • কোণ একটা Array এর ভেতরে “islam” নামটা আছে কিনা সেটা কিভাবে চেক করতে পারি ? অবশ্যয় .indexOf() এর ফাংশন তা দিয়ে । কিন্তু আমরা এখন অন্য একটা কিছু দিয়ে এই কাজটা করার চেস্টা করব । সেটা আর কিছু না । সেটা হচ্ছে .includes()

 

const friends = [

  "rashedul islam shihab","rashedul", "islam","shihab"

];

const a = friends.includes("islam");

console.log(a);

 

 

  • এবার আমরা array কাটাকাটি দেখব। arr slice করলে আগের original Array আগের মতই থাকে । original Array চেঞ্জ হয় না ।

 

const num = [1, 2, 3, 4, 5, 6];

const numSlice = num.slice(3, 5); //কত নাম্বার ইনডেক্স হতে কত পর্যন্ত দেখতে চাই

console.log(numSlice);

console.log(num);

 

  • .splice এর কাজ কি ? .splice করলে আমাদের original Array থেকে যে ইনডেক্স গুলোকে রিমুভ করতে চাচ্ছি সেগুলা রিমুভ হয়ে যাবে

 

const num = [1, 2, 3, 4, 5, 6];

const numSplice = num.splice(3, 2); //৩ নং ইনডেক্স এর পর ২ তা ইনডেক্স রিমুভ করবে এবং console এ আউটপুট দেখাবে [৪,৫]

console.log(numSplice);

console.log(num);// original Array থেকে [৪,৫] রিমুভ হয়ে যাবে

 

  • .splice করার পরে আমরা দেখলাম original Array এর এলিমেন্ট এর ভিতরের ভেলু রিমুভ হয়ে যায় । কিন্তু আমরা কি সেখানে আর কিছু আদ্দকরতে পারব না ? অবশ্যয় পারব ।

 

const num = [1, 2, 3, 4, 5, 6];

const numSplice = num.splice(3, 2, 10, 20, 30);// রিমুভ হওয়া যায়গায় ১০,২০,৩০ অ্যাড হয়ে যাবে / এর সাথে আরও নাম্বার অ্যাড করতে পারি .অথবা একটা নাম্বার add করতে পারি ।

console.log(numSplice);

console.log(num);

 

  • .sort() ও .reverse() এর কাজ কি ?

 

const num = [1, 2, 5, 4, 6, 5, 1, 2, 3].sort();

const fnds = ["arman", "rashedul", "cad", "babul", "ebul"].sort();

const numReverse = num.reverse();

const fndsReverse = fnds.reverse();

console.log(num);console.log(fnds);

console.log(numReverse);console.log(fndsReverse);

 

  • আমরা যদি ২ সংখ্যা বা তিন সংখ্যার কোণ নাম্বারকে .sort() করতে চাই তাহলে .sort() ঠিক মত কাজ করে না । তার কারণ হচ্ছে ২বা৩ সঙ্খার নাম্বাররের প্রথম সংখ্যাকে ধরে Sort করে । উদাহরণ লাল চিহ্নিত করা আছে ।  তাই আমরা একটা ফাংশন এর সাহায্য নিতে পারি

 

const number = [11, 2, 3, 6, 4, 8, 12, 63, 58, 22, 100].sort(function (a, b){

  return a - b; });

console.log(number);

 

  • উদাহরণ দেখে বুঝতে হবে এখানে কি কাজ করা হয়েছে Module 28-7

 

 

 

  • Try Catch Finally এর কাজ কি ? error handle করা ।

 

try{

 

}catch{

 

}finally{

    

}

 

  •  

 

 

All module link

আর আমার github এ যাইতে চাইলে এই লিঙ্কে ক্লিক করুন

About

Md: Rashedul Islam Shihab

Writer of this note

Batch4

Social accounts


 

 

أحدث أقدم