💡 สวัสดีจ้าเพื่อน ๆ วันนี้แอดจะพาเพื่อน ๆ มารู้จักกับ Operator จาก JavaScript ที่จะช่วยให้เพื่อน ๆ เข้าถึงข้อมูลใน Object ได้ง่ายมากขึ้น !!
.
🌈 และเจ้านี่คือ...Optional chaining (?.) นั่นเองจ้า จะเป็นยังไง มีรายละเอียด และวิธีการใช้งานยังไง ไปติดตามกันได้ในโพสต์นี้เลยจ้า ~~
.
✨ Optional chaining (?.) - เป็นตัวดำเนินการที่ทำให้เราสามารถอ่านค่าใน Object ที่ซ้อนกันหลาย ๆ ชั้นได้ง่ายมากขึ้น เขียนง่าย และทำให้โค้ดสั้นลงนั่นเอง
.
จริง ๆ แล้วมันก็เหมือนเราใช้ เครื่องหมายจุด (.) นั่นแหละ แต่ความพิเศษของมันก็คือถ้าในกรณีไม่มีค่าใน Object หรือ Function มันจะ Return เป็น Undefined แทน Error
.
👨💻 Syntax
.
obj.val?.prop
obj.val?.[expr]
obj.arr?.[index]
obj.func?.(args)
.
📑 วิธีการใช้งาน
.
❤️ ตัวอย่าง 1 : ใช้เข้าถึงข้อมูลใน Object
let customer = {
name: "Mew",
details: {
age: 19,
location: "Ladprao",
city: "bangkok"
}
};
let customerCity = customer.details?.city;
console.log(customerCity);
//output => bangkok
.
❤️ ตัวอย่าง 2 : ใช้กับ Nullish Coalescing
let customer = {
name: "Mew",
details: {
age: 19,
location: "Ladprao",
city: "bangkok"
}
};
const customerName = customer?.name ?? "Unknown customer name";
console.log(customerName); //output => Mew
.
❤️ ตัวอย่าง 3 : ใช้กับ Array
const obj1 = {
arr1:[45,25,14,7,1],
obj2: {
arr2:[15,112,9,10,11]
}
}
console.log(obj1?.obj2?.arr2[1]); // output => 112
console.log(obj1?.arr1[5]); // output => undefined
.
📑 Source : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining
.
borntoDev - 🦖 สร้างการเรียนรู้ที่ดีสำหรับสายไอทีในทุกวัน
#javascript #optionalchaining #BorntoDev
同時也有2部Youtube影片,追蹤數超過12萬的網紅prasertcbs,也在其Youtube影片中提到,การเขียนฟังก์ชันที่ส่งค่ากลับมาเป็นอะเรย์ โดยใช้ตัวอย่างสมการ quadratic การใช้งาน list() เพื่อกำหนดตัวแปรที่รับค่าจากอะเรย์...
「function return array」的推薦目錄:
- 關於function return array 在 BorntoDev Facebook 的最讚貼文
- 關於function return array 在 BorntoDev Facebook 的最讚貼文
- 關於function return array 在 BorntoDev Facebook 的最佳貼文
- 關於function return array 在 prasertcbs Youtube 的精選貼文
- 關於function return array 在 prasertcbs Youtube 的最佳貼文
- 關於function return array 在 Return array in a function - c++ - Stack Overflow 的評價
- 關於function return array 在 How To Return An Array From A Function - YouTube 的評價
- 關於function return array 在 How to return an array from a function - YouTube 的評價
- 關於function return array 在 JavaScript Array.from() Method 的評價
- 關於function return array 在 return array in solidity - GitHub 的評價
- 關於function return array 在 Returning an int array from a function - Arduino Stack Exchange 的評價
function return array 在 BorntoDev Facebook 的最讚貼文
🔥 เพื่อน ๆ รู้กันไหมว่า เจ้าตัว Function ของ Python นั้น สามารถ Return ค่าได้มากกว่า 1 ค่า !!
.
👉 ซึ่งจากปกติแล้วการ Return ค่าของ Function (Java เรียกว่า Method) ในภาษา C, C++ หรือ Java จะสามารถส่งค่ากลับได้แค่ค่าเดียวเท่านั้น ถ้าเราต้องการที่จะส่งกลับค่าออกมาจาก Function ที่มากกว่าหนึ่งตัว เราจะใช้หลักการ Return ค่ากลับออกมาเป็น Array, List หรือ Class ของ Java (หรืออื่น ๆ ที่สามารถรวมข้อมูลหลาย ๆ ตัวเป็นก้อนเดียวได้)
.
✨ แต่เจ้าตัว Python นั้นสามารถ Return ตัวแปรหลาย ๆ ตัวออกมาได้ทันที โดยที่เราไม่จำเป็นต้องอัดข้อมูลให้เป็นก้อนเดียวก่อนส่งออก เพราะเจ้าตัว Function จะทำการ Pack ข้อมูลเป็น Tuple ให้เองเลยโดยอัตโนมัติ (Tuple คือกลุ่มข้อมูลที่มีรูปแบบคล้าย List แต่ไม่สามารถแก้ไขข้อมูลในนั้นได้)
.
📑 ตัวอย่างเช่น เราต้องการที่จะส่งค่าตัวแปรกลับ 3 ตัว เราก็สามารถใช้ตัวแปร 3 ตัวในการรอเก็บค่าที่ส่งออกจาก Function ได้ทันทีเลย แบบดังรูป (สุดท้ายเจ้า Function ของ Python ก็ return ออกมาแค่ค่าเดียวนั่นแหละ นั่นก็คือ Tuple นั่นเอง)
.
borntoDev - 🦖 สร้างการเรียนรู้ที่ดีสำหรับสายไอทีในทุกวัน
function return array 在 BorntoDev Facebook 的最佳貼文
🎁 วันนี้มาพบกับช่วงของดีบอกต่อกับคอร์ส TypeScript Course for Beginners 2021 จากช่อง Academind ที่จะทำให้เราเขียน Typescript เป็นภายใน 3 ชม. !!
.
📚 คลิปนี้ประกอบด้วยเนื้อหาที่จะช่วยให้เราเข้าใจ Typescript ซึ่งเล่าตั้งแต่ที่มา และยังเข้าใจความแตกต่างของ TypeScript และ JavaScript อีกด้วยนะ แถมยังเป็นการสอนแบบอธิบายโค้ดให้ดูเลย เข้าใจง่ายมากเลยคร้าบบ
.
⚡สำหรับคลิปนี้ประกอบด้วยเนื้อหาดังนี้ (อ้างอิงจาก Timestamp)
✅Getting Started
✅What is TypeScript
✅Installing & Using TypeScript
✅The Advantages of TypeScript
✅Course Outline
✅How to Get the Most out of This Course
✅Setting Up our Development Environment
✅The Course Project Setup
✅Module Introduction
✅Using Types
✅TypeScript Types vs JavaScript Types
✅Numbers, Strings and Booleans
✅Type Assignment and Type Inference
✅Object Types
✅Array Types
✅Tuples
✅Enums
✅The Any Type
✅Union Types
✅Literal Types
✅Type Aliases
✅Function Return Types and Void
✅Function Types
✅Function Types and Callbacks
✅The Unknown Type
✅The Never Type
✅Wrap Up
✅Module Introduction
✅Watch Node
✅Compiling the Entire Project
✅Include and Exclude Files
✅Setting a Compilation Target
✅Understanding TypeScript Libs
✅More Options
✅Source Maps
✅Rootdir and Outdir
✅noemit on Error
✅Strict Compilation Options
✅Code Quality Options
✅Debugging with Visual Studio Code
✅Wrap Up
.
💥ถ้าใครสนใจคอร์สนี้ กดลิงค์เข้าไปเรียนกันเลยจ้า !!! >>
https://www.youtube.com/watch?v=BwuLxPH8IDs
.
borntoDev - 🦖 สร้างการเรียนรู้ที่ดีสำหรับสายไอทีในทุกวัน
function return array 在 prasertcbs Youtube 的精選貼文
การเขียนฟังก์ชันที่ส่งค่ากลับมาเป็นอะเรย์ โดยใช้ตัวอย่างสมการ quadratic
การใช้งาน list() เพื่อกำหนดตัวแปรที่รับค่าจากอะเรย์

function return array 在 prasertcbs Youtube 的最佳貼文
Convert each row in Excel to JSON's array element.
Get the converter file from http://goo.gl/h2nxAK
Important Note++: Due to the limitation of Excel that each formula will not be able to return more than 32,767 characters, hence the jsonArray() function I created will return #VALUE! if the output exceeded 32,767 characters. The workaround is to partially convert the ranges and combine them together in the normal text editor. Don't forget to remove extra square brackets [.

function return array 在 How To Return An Array From A Function - YouTube 的推薦與評價

How to return an array from a function in C. We technically cannot return an array from a function in C, but we can use pointers, ... ... <看更多>
function return array 在 How to return an array from a function - YouTube 的推薦與評價

At least once, we've all tried returning an array type from a function and it failed horribly. Here's how to do it properly. ... <看更多>
function return array 在 Return array in a function - c++ - Stack Overflow 的推薦與評價
... <看更多>
相關內容