Automatically translated.View original post

forEach/JavaScript

# Web Site Writing Basics

# javascript

# Each

Access to Array members with forEach in JavaScript is a simple and popular iterate method. Use the Array.prototype.forEach method (). Each forEach application will call callback function once for every member in the syntax array. JavaScriptarray.forEach (callback (currentValue, index, array), thisArg);

The function callback description parameter (Required) to be run for each member in the current member currentValue array that is processing the index (Optional) index (index) of the current member array (Optional) the array that is processing thisArg (Optional). The value to be used as this. When running the code sample callback, this is the sample accessing the member in the array and displaying it. JavaScriptconst fruits = ["Apple," "Banana," "Cherry," "Date"];

/ / 1.Just access the value of the member (current value)

console. log ("--- Just access the value ---");

Fruits. Each (function (fruit) {

console. log (fruit);

});

/ / Output:

/ / Apple

/ / Banana

/ / Cherry

/ / Date

/ / 2.Access both values and indexes (currentValue, index) - Arrow Function is recommended

Console.log ("\ n--- Access to values and indexes ---");

Fruits. Each (fruit, index) = > {

console.log ('Fruit at index ${index} is: ${fruit}');

});

/ / Output:

/ / Fruit at index 0 is: Apple

/ / Fruit at index 1 is: Banana

/ / Fruit at index 2 is: Cherry

/ / Fruit at index 3 is: Date

Break / Return: Each forEach is designed to always process every member. If you need a mechanism to stop loops first, you should use a loop for or other methods such as some or every instead of no return value: the forEach method will always restore undefined. Unlike the map or filter method that returns to a new array, change the original value: the callback function can change the original array. If you change the value of the current value, it will not change the value of the array, but if you modify the object located in the array (such as the array of objects). ) That change will affect the original array.

2025/10/19 Edited to

... Read moreเมธอด forEach ใน JavaScript ถือเป็นเครื่องมือที่ช่วยเขียนโค้ดให้เข้าใจง่ายขึ้นสำหรับการวนซ้ำสมาชิกใน Array อย่างไรก็ตาม หลังจากที่ได้ลองใช้จริง ผมพบว่ามันเหมาะอย่างยิ่งสำหรับงานที่ต้องการประมวลผลหรือแสดงผลข้อมูลใน Array แต่ไม่เหมาะกับกรณีที่ต้องการหยุดลูประหว่างกลาง เพราะ forEach ไม่รองรับการใช้ break หรือ return เพื่อออกจากลูป นอกจากนี้ forEach จะไม่มีค่าคืนกลับมาใช้ในผลลัพธ์ ซึ่งต่างจากเมธอด map หรือ filter ที่ส่งคืน Array ใหม่ ในการพัฒนาจริง ผมจึงมักจะเลือกใช้ forEach เมื่อต้องการประมวลผลข้อมูลและแสดงผลอย่างเดียว และใช้ map หรือ filter เมื่อจำเป็นต้องแปลงข้อมูลหรือกรองข้อมูลเป็น Array ใหม่ อีกอย่างหนึ่งที่น่าสนใจคือการเข้าใจว่าการเปลี่ยนแปลงค่าภายใน callback ของ forEach จะไม่ส่งผลต่อสมาชิกเดิมใน Array หากเป็นค่าธรรมดา (primitive) แต่หากสมาชิกใน Array เป็นออบเจกต์ การแก้ไขออบเจกต์ใน callback จะส่งผลกับ Array ต้นฉบับด้วย เช่น การเพิ่มหรือลบค่าในออบเจกต์ ทำให้ต้องระวังการเปลี่ยนแปลงข้อมูลโดยไม่ได้ตั้งใจ สุดท้าย การใช้งาน forEach ร่วมกับรูปแบบ Arrow Function จะช่วยให้โค้ดสั้นลงและอ่านง่ายขึ้น เช่น การใช้ (value, index) => { ... } และผมแนะนำให้ฝึกเขียนโค้ดด้วยรูปแบบนี้บ่อย ๆ เพราะนอกจากสวยงามแล้วยังช่วยลดข้อผิดพลาดในเรื่องของ this และ context ได้ด้วย

Related posts

My Programming Interest Just Skyrocketed! 🚀
I just discovered something that has made my interest in programming explode to 1000000000000000%! 🤯 🎮 Learning Programming is Like a Game Adventure! From Python, Java, JavaScript, to HTML, there are all kinds of programming languages available, along with systematic topic courses. The learning p
Valder

Valder

2173 likes

A dark image showing code on a screen and a keyboard, with text overlays "Top 10 Free Online Courses with Certificates" and "SWIPE FOR MORE," indicating a list of educational resources.
A collage of four logos for online learning platforms: Google Digital Garage, Harvard University, Coursera, and LinkedIn Learning, highlighting various educational opportunities.
A collage of four logos for online learning platforms: Alison, The Open University, a green hexagonal logo with a figure and leaves, and a purple upward-pointing arrow logo.
Top 10 Free Online Courses W/ Certificates
With me having no friends😅 I try and find resourcesful tool and reasouces I can use to better myself in difficult skill aspects! I’ve actually tried a couple of these and currently using Udemy rn! It’s never ending courses. Here’s details on each website! Would you try and of these? Also this is my
Iamnariah

Iamnariah

13.3K likes

A scenic view of a coastal town with white buildings and blue sea, featuring text overlay "3 websites for free tech certifications BEGINNER FRIENDLY".
A person in a straw hat looking at a white-washed coastal town, with text overlay "1. Google Skillshop Google Analytics Individual Qualification Google Ads Certifications".
A person looking at a white-washed coastal town with pink flowers, featuring text overlay "2. Microsoft Learn Microsoft Azure Fundamentals Power BI Data Analyst Associate".
3 websites for free tech certifications - beginner
1. Google Skillshop - What It Offers: Free certifications in Google products like Google Analytics, Google Ads, and Google Cloud. - Best For: Digital marketing, data analysis, and cloud computing beginners. - Key Certifications: - Google Analytics Individual Qualification
vedha | career tips (tech) 👩‍

vedha | career tips (tech) 👩‍

916 likes

A person's hand is on a MacBook Pro keyboard, displaying the coddy.tech website with "Code Makes Perfect" and coding illustrations. The image highlights learning to code for free with this website.
A MacBook Pro screen shows the coddy.tech website's daily challenge interface, allowing users to search by programming language, choose difficulty, and access daily challenges.
A MacBook Pro screen displays the coddy.tech website, showcasing full, beginner-friendly courses like "SQL for beginners" and "Python Introduction," emphasizing practicing at one's own pace.
learn how to code for FREE! 💻
learning to code for free has never been easier with coddy.tech! 🌟 whether you're a complete beginner or looking to enhance your skills, coddy.tech offers a range of resources to help you on your coding journey. here's how you can get started: explore coding courses: coddy.tech provides
sanae ☕️

sanae ☕️

1412 likes

A laptop displays coding terminal output with a keyboard in the foreground, featuring the text "BEST AI Tutor for Coding," highlighting an AI-powered programming learning platform.
BEST AI Tutor for Coding
Best AI Tutor for Coding in 2026? This Is What Serious Learners Are Switching To Most people don’t fail at coding because it’s hard. They fail because they’re learning alone. Watching tutorials. Copying code. Getting stuck. Quitting. BootSelf changes that. BootSelf is an AI-powered coding tuto
Code with BootSelf AI

Code with BootSelf AI

17 likes

A laptop, a Starbucks drink, and a muffin on a wooden table, with the overlaid text "5 WEBSITES TO LEARN PROGRAMMING FOR BEGINNERS".
A MacBook Air displaying the FreeCodeCamp website, which offers free coding lessons and certifications. The text "FREECODECAMP" with an arrow points to the screen.
A MacBook Air showing the Codecademy website, featuring its basic, plus, and pro pricing plans. The text "CODECADEMY" with an arrow points to the screen.
Learn programming for free 👩‍💻
1. FreeCodeCamp - Languages: JavaScript, Python, SQL, HTML/CSS, and more. - Hands-on Projects: FreeCodeCamp is project-driven, meaning as you go through the curriculum, you'll build real-world applications like weather apps, portfolio websites, and data visualization projects. The full-
vedha | career tips (tech) 👩‍

vedha | career tips (tech) 👩‍

612 likes

BOOST Your Career: 4 FREE Online Courses for You
Are you wanting to up your resume and LinkedIn profile? There are so many ways to go about it, but free courses can really help! Here are a few sites with free courses to take. Harvard + EdX Price: Free Course Topics: Computer Science, Programming with Python, Artificial Intelligence with Pyth
Itsleilahclaire

Itsleilahclaire

1732 likes

UI Designer - tips for a career
1. Learn the Fundamentals of UI Design -Basic Design Principles: -Typography: Learn how to use fonts effectively (size, hierarchy, readability). -Color Theory: Understand color combinations, palettes, and contrast. -Layout and Grids: Study alignment, spacing, and grid systems.
vedha | career tips (tech) 👩‍

vedha | career tips (tech) 👩‍

27 likes

A woman works on a laptop by a large window overlooking a city skyline, with the title "Top Free Platforms To Learn Coding" overlaid.
The Codecademy logo is displayed above a text box detailing its interactive coding lessons, quizzes, and projects for beginners, set against an orange cityscape.
The Coursera logo is shown above a text box explaining its free coding courses from universities, including assignments and peer-reviewed projects, against an orange cityscape.
Top Free Platforms to Learn Coding
If you aren’t sure if coding it for you, there are multiple free platforms you can check out to give it a shot! I started learning how to code through the following platforms around 5 years ago, loved it and decided to major in Computer Science at University of Maryland, and am now a software engin
anjali.gama

anjali.gama

309 likes

A person is shown coding at a desk in a dimly lit room, with a computer monitor displaying lines of code. The image features text overlay 'TOP 5 PROGRAMMING LANGUAGES FOR BEGINNERS' and a 'LEARN MORE' button, aligning with the article's theme of starting to code.
A computer setup displays a list of the 'TOP 5 PROGRAMMING LANGUAGES FOR BEGINNERS': Python, JavaScript, Java, C++, and Scratch. Each language includes a brief description and an icon, directly illustrating the article's main content.
A neon-lit desk setup features a computer displaying a purple galaxy wallpaper. An overlay asks, 'COMMENT IF YOU'LL TRY CODING IN 2025!', serving as a call to action related to the article's theme of learning to code.
2025 Is The Year You Learn How To Code 👾💜
Top 5 Programming Languages for Beginners Starting your coding journey can be overwhelming, but choosing the right language makes all the difference. Here are five beginner-friendly programming languages, each with its own strengths, to help you get started. Python is a favorite for beginners
CompSkyy

CompSkyy

60 likes

Study For Hours With These Tricks!
Studying for hours can feel impossible sometimes, but I’ve learned to outsmart my own procrastination by using a few simple tricks. The first is the “5-minute rule.” Whenever I’m struggling to start, I tell myself, “I’ll just study for 5 minutes.” It’s such a small commitment that it feels easy to
CompSkyy

CompSkyy

350 likes

5 Learn to Code Sites You Haven’t Heard Of
If you’re learning computer programming and want to know where to find FREE intermediate resources…here are some that I like! Let me know if you’ve used any. 1. FullStackOpen Free courses focused on building web apps. They teach React Native, GraphQL, Typescript, Containers and Database
Study Seal

Study Seal

241 likes

A smiling woman in a light blue suit sits on a sofa, with text overlays "Build a Winning Tech Portfolio" and "with These Top Online Courses" featuring a folder icon. The Lemon8 logo and username are at the bottom.
A woman wearing headphones smiles while looking right, with a microphone and lamp nearby. An overlay describes "1. Coursera's Full Stack Web Development Specialization" and its benefits for practical web development experience.
A smiling woman holds a white mug. An overlay describes "2. Data Scientist Nanodegree" and its benefits for providing deep insights into data science with actionable projects and mentorship.
Discover the best courses to show your skills ✨
Looking to build an impressive tech portfolio that your skills and sets you apart from the competition? A standout portfolio can be a game-changer in landing your dream job. Here are some top online courses that offer hands-on projects and portfolio-building elements to help you create a compelling
Dominica Amauri

Dominica Amauri

64 likes

A woman in a car with the text overlay "BREAK INTO TECH 5 PRACTICAL STEPS," serving as the title image for an article on career advice.
A car interior view with text overlays detailing the first two steps to break into tech: "1. Learn the Fundamentals of Programming" and "2. Specialize in a Tech Area."
A scenic view of a city skyline and water with text overlays outlining the remaining steps: "3. Build a Portfolio," "4. Network in the Tech Community," and "5. Gain Practical Experience Through Internships or Freelancing."
BREAK INTO TECH FROM ANY INDUSTRY 👩‍💻
1. Learn the Fundamentals of Programming - Details: Mastering basic programming skills is crucial for many tech roles. Languages like Python, JavaScript, and Java are widely used and are great starting points for web development, data science, and software engineering. Understanding programming
vedha | career tips (tech) 👩‍

vedha | career tips (tech) 👩‍

84 likes

A desk setup with a monitor displaying a SheCodes workshop on 'React States,' titled 'how i learned to code.' The image shows a keyboard, mouse, and speaker, with 'Upgrade your career' text, reflecting the user's coding journey with SheCodes.
How I learned to code
I enrolled in SheCodes last year and it has been the best decision that I have made regarding my career! 🌼I did their free class and I knew immediately I was a good fit. Starting out with basics I tested if my brain could work well with code and once I learned it did I moved on to the max progr
Realm of Comfort

Realm of Comfort

533 likes

5 entry level tech jobs for newbies 👩‍💻☁️
1. Entry-Level Software Engineer - What they do: Write and test code, work on software features, fix bugs, and collaborate with other developers. - Education: Bachelor’s degree in Computer Science, Software Engineering, or a related field. - Skills: Proficiency in programming langua
vedha | career tips (tech) 👩‍

vedha | career tips (tech) 👩‍

535 likes

A pink mechanical keyboard with glowing keys and colorful string lights, overlaid with text that reads "LEARN SOFTWARE DEV FOR FREE 6 RESOURCES," indicating a guide to free software development learning.
A guide titled "1. LEARN THE INTERNET" for beginners, listing key concepts like HTTPS and DNS. It recommends "Front End Masters - Sections 1-4" and shows the cover of "The Front End Developer/Engineer Handbook 2024."
A guide titled "2. LEARN HTML/CSS" for beginners, highlighting key concepts like web page structure and CSS Flexbox. It recommends "FreeCodeCamp - Responsive Web Design Course" and displays a screenshot of the course page.
Study to be a Frontend Dev - Roadmap (100% Free)
This is a study guide for becoming a Front End Developer! All resources mentioned are FREE. Don’t pay anyone for this info! Why am I not recommending a zero to job course? Two Reasons 1-There is no course that will teach you everything 2-You need to put in some sweat equity, only wat
Study Seal

Study Seal

688 likes

A hand holds a black remote control, still in its plastic packaging, and a white box, against a blurred background of a TV and shelf. Text overlay reads 'SHEIN FINDS Must haves'.
A close-up shows a hand holding a black remote control with various buttons, including a purple directional pad and quick access buttons for streaming services like Netflix, Hulu, YouTube, and Disney+.
A screenshot displays multiple online listings for a black remote control compatible with TCL Roku TV, showing images of the remote, prices, and a 'Repurchase' button for each item.
$3.00 each
I know I can’t be the only one tired of losing controllers to the dang TV .📺 y’all better run to the SHEIN this is like y’all. They’re going to my kids stocking stuffers. I’m tired of them using my phone to change the channel. Lol. #lemon8christmas #l8r2023 #shein #sheinfinds #Lemon8Di
🐝L E X 🩺

🐝L E X 🩺

3745 likes

The image introduces "DUOLINGO DUPES TO LEARN HOW TO CODE (for free!)" with icons for Mimo, Encode, and Sololearn apps, set against a light blue background with floral patterns.
The image details the Mimo app, showcasing its icon, career paths like Full-Stack Developer and Python AI Developer, and a description of its courses in Python, SQL, JavaScript, and more.
The image highlights the Encode app, displaying its icon, a "LEARN TO CODE" interface, and lesson topics such as Swift Basics and Reusing Code, along with a description of its interactive lessons.
✨CALLING ALL THE TECH GIRLS 🖥️ ✨
Learning to code was never on my radar—until life nudged me in the right direction. As the granddaughter of a brilliant I.T. professional, I didn’t fully appreciate his advice to dive into tech until after his passing in 2021. Now, I’m honoring his legacy by teaching myself to code, one step at a t
✿ Jaide ✿

✿ Jaide ✿

142 likes

A laptop, coffee mug, and notebook on a wooden desk, with an overlay text reading 'Free projects for Computer Science Majors', indicating resources for CS students.
A MacBook displaying the GeeksforGeeks website's 'Computer Science Projects' page, showing project ideas and trending topics for computer science students.
A MacBook displaying the UpGrad blog post titled '33 Best Computer Science Project Ideas & Topics For Beginners To Experts [Latest 2024]', offering project inspiration.
Free hands on projects for CS majors 👩‍💻
1. GeeksforGeeks – Computer Science Projects - I love browsing GeeksforGeeks because they provide a huge variety of project ideas, from simple web development to advanced machine learning. Each project comes with a step-by-step guide, which makes it super easy to dive in! 💻✨ https://www
vedha | career tips (tech) 👩‍

vedha | career tips (tech) 👩‍

159 likes

A smartphone displaying Adobe Creative Cloud apps like Lightroom, Photoshop Express, and Acrobat Reader, held over pink mechanical keyboards. The image has a text overlay that reads "STUDENT DISCOUNTS."
A graphic titled "1. PREMIUM LEARNING [Student Discounts]" listing student offers for Babbel, Lingvist, CodeAcademy Pro, DataCamp, and Skillshare, alongside an "INTERACTIVE COURSES" graphic.
A graphic titled "2. MENTAL HEALTH [Student Discounts]" listing student offers for Headspace and Spotify Premium, accompanied by a screenshot of the Headspace app interface.
Student Software + Learning Discounts
If you have a valid student email or ID, you probably qualify for these! Even if you’re an adult “going back to school” - these apply to you too! All prices are in USD. Premium Learning Babbel - 3 months for $15.99 Lingvist - $39.99/year Codeacademy Pro $150/year Datacamp - $149/year
Study Seal

Study Seal

309 likes

A character sheet portrait of a smiling woman, a 52-year-old mom of seven, surrounded by elements reflecting her organized, resilient life. It highlights her journey balancing family, personal growth, and learning technology like Python, JavaScript, and SQL, with daily routines, goals, and affirmations for managing anxiety and ADHD.
🌹 From Python, JavaScript and SQL Books to Code Dreams: This Is Me
🌹 From Budget Books to Code Dreams: This Is Me This beautiful character-sheet portrait captures me being organized, resilient, and focused on growth. I am surrounded by planners, notebooks, coding references, roses, and inspirational reminders, I represent the perfect blend of determination and
mirandaperry05

mirandaperry05

1 like

3 Tips For Online Classes!!
Online classes can be a game-changer, but let’s be real—they’re not always easy. Staying motivated when your bed is right there? A struggle. 🙃 But with the right approach, you can absolutely thrive in virtual learning. Let’s break it down! → Create a Dedicated Study Space Having a spot that’s j
CompSkyy

CompSkyy

268 likes

A man with tattoos and a cap sits at a desk, coding on a large monitor in a dimly lit room. Text overlays read 'SWIPE', 'Learning JavaScript?', and 'This is for YOU!', with a thinking emoji, promoting coding education.
A man with headphones and a cap codes at a desk with a large monitor displaying code. Text overlays read 'SWIPE', 'Break vs Continue', and 'In JS loops', with a thinking emoji, highlighting JavaScript loop concepts.
A man with headphones and a cap sits at a desk, coding on a large monitor in a bright room. Text overlays read 'Let's Discuss!' with a thinking emoji, inviting interaction about coding topics.
Coding W/ JavaScript?
As a software engineer w/ ADHD, understanding the difference between certain syntax keywords is critical, such as ‘continue’ and ‘break’ within JavaScript loops.💡 It’s almost like centering a <div> — it takes practice to feel confident in your abilities. 🛠️ When my mind gets stuck in a
Michael Burbank

Michael Burbank

13 likes

TOP WAY TO MAKE MONEY
Becoming a freelance web developer is a great way to make money. First, build your skills by learning HTML, CSS, and JavaScript, and then move on to frameworks like React or Angular, and back-end languages like Node.js, Python, or PHP. Understanding web design principles and practicing responsive d
Kaliania

Kaliania

86 likes

Vocational Careers For YOU✨
Hey There✨ Vocational careers are focused on practical, hands-on skills and training for specific trades or professions. These careers typically require less time and financial investment than a traditional four-year college degree and are often taught at trade schools, community colleges, or th
Emilyyy

Emilyyy

97 likes

4 Popular Programming languages of 2024
1. JavaScript Prerequisites: A basic understanding of HTML and CSS is recommended for effective web development with JavaScript. Platforms: Web browsers, server-side environments with Node.js. Use Cases: - Creating interactive web elements - Building dynamic web applications - Developing sing
vedha | career tips (tech) 👩‍

vedha | career tips (tech) 👩‍

25 likes

How I’d Learn JavaScript If I Were Starting Again
#javascript #coding #programming #tech #codingforbeginners
Aysha

Aysha

124 likes

coding languages worth learning for students 2024
as a cs grad, staying updated with in-demand languages is crucial. Things change quickly in tech, so being adaptable and learning as you go ensures you’ll be competitive and well-informed no matter what your career is. here are some of my top picks for this year: python - versatile and essential f
vvanessaww

vvanessaww

16 likes

🐉 DRAGON OF COLD FIRE 🐺 Online Game for Solo Play
Dragon of Cold Fire is currently in development as an online interactive ritual game—designed for once-per-day engagement, where players forge soul, track flame, and decode emotional legacy through sovereign responses. This is not a guessing game. It’s a mythic mirror. Players are guided towar
Jeanne Mifflin

Jeanne Mifflin

0 likes

See more