Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript
JavaScript
  1. Regex - ใช้ Pattern ซ้ำเพื่อ Capture Groups ใน JavaScript

    วิธีทำ ใช้ Regular Expression กับ backreference (\1, \2) เพื่อจับ pattern ที่ซ้ำกัน ตัวอย่างโค้ด var groupValues1 = 10 10 10; var groupValues2 = 10 10 10 10; var groupValues3 = 10 10; var regularExpression = /^(\d+)(\s)\1\2\1$/; var isValidGroup1 = regularExpression.test(groupValues1); var isVa

  2. ไม่สามารถ Push ทุก Elements ของ Stack เข้า Stack อื่นด้วย For Loop ใน JavaScript

    หลักการ Stack ทำงานแบบ LIFO (Last In First Out) ต้อง pop() ทุก elements จาก stack แรก แล้ว push() เข้า stack ที่สอง ตัวอย่างโค้ด var myFirstStack=[10,20,30,40,50,60,70]; var mySecondStack=[]; for(;myFirstStack.length;){ mySecondStack.push(myFirstStack.pop()); } console.log(After popping all e

  3. รวม 2 Arrays ให้เป็น Array of Objects ใน JavaScript

    ข้อมูลตัวอย่าง var firstArray = [John, David, Bob]; var secondArray = [Mike,Sam,Carol]; วิธีทำ ใช้ map() จาก JavaScript ตัวอย่างโค้ด var firstArray = [John, David, Bob]; var secondArray = [Mike,Sam,Carol]; var arrayOfObject = firstArray.map(function (value, index){ return [value, secondArray[i

  4. ความยาวของ JavaScript Object

    ข้อมูลตัวอย่าง var studentObject = new Object(); studentObject[studentFirstName] = John; studentObject[studentLastName] = Doe; studentObject[studentAge] = 22; studentObject[studentCountryName] = US; studentObject[studentCollegeName] = MIT; studentObject[studentSubjectName] = JavaScript; วิธีหา

  5. วิธีเรียกใช้ Parent's Method เมื่อ Child มี Method ชื่อเดียวกันใน JavaScript

    เพื่อเรียกใช้ Parent Method เมื่อ Parent และ Child มี Method ชื่อและ Signature เหมือนกันคุณสามารถใช้ไวยากรณ์ด้านล่างนี้console.log(YourParentClassName.prototype.yourMethodName.call(yourChildObjectName));ตัวอย่างclass Super {    constructor(value) {       this.value = value;

  6. กรอง JSON Data ที่มี Multiple Objects ใน JavaScript

    วิธีทำ ใช้ filter() ร่วมกับการเปรียบเทียบ == ตัวอย่างโค้ด const jsonObject= [ { studentId:101, studentName:David }, { studentId:102, studentName:Mike }, { studentId:103, studentName:David }, { studentId:104, studentName:Bob } ] var result = jsonObject.filter(obj=> obj.studentName ==

  7. หา Element แรกของ Array ใน JavaScript

    วิธีทำ ใช้ for loop พร้อม if-else ตรวจสอบความยาว array ตัวอย่างโค้ด 1){ for(var index=0; index < studentDetails.length; index++){ firstObjectValue = studentDetails[index].firstName; break; } } else { firstObjectValue = undefined; } if(firstObjectValue != undefined) console.

  8. เปลี่ยนค่า Nested Object Keys ใน JavaScript

    วิธีทำ ใช้ dot notation (.) ร่วมกับ square brackets ([]) เข้าถึง nested properties ตัวอย่างโค้ด var details = { customer: { customerDetails: { otherDetails: [ { customerDetails: { isMarried: false } }, { customerDetails: { isMarried: false } }, { customerDet

  9. นับจำนวน Child Nodes ใน JavaScript

    วิธีทำ ใช้ children.length เพื่อนับจำนวน child nodes ตัวอย่างโค้ด <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Docume

Total 5941 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:101/298  20-คอมพิวเตอร์/Page Goto:1 95 96 97 98 99 100 101 102 103 104 105 106 107