Search
Close this search box.
Search
Close this search box.
Search
Close this search box.

How to dump the for loop and stay alive

Facebook
Twitter
LinkedIn
Pinterest
WhatsApp
var arr  ['a', 'b', 'c', 'd', 'e'];
for (var i  0; i < arr.length; i++) {
  console.log(arr[i]);
}

The example array

var people  [{
  id: 1,  
  name: 'Alice',
  age: 16
},
{
  id: 2,
  name: 'Bob',
  age: 19
},
{
  id: 3,
  name: 'Carol',
  age: 15
},
{
  id: 4,
  name: 'David',
  age: 21
}];

Sum an array

var sum  0;for (var i  0; i < people.length; i++) {
  sum += people[i].age;
}
const sum  people.reduce(function(acc, person){
  return acc + person.age;
}, 0)
const sum  people.reduce((acc, person) > (acc + person.age), 0);

Interlude: a note about arrow functions

Filter an array

var adults  [];for (var i  0; i < people.length; i++) {
  if (people[i].age > 16) {
    adults.push(people[i]);
  }
}
const adults  people.filter(person > person.age > 16);

Find the element with max property

var oldest  {age: 0};for (var i  0; i < people.length; i++) {
  if (people[i].age > oldest.age) {
    oldest  people[i];
  }
}
const oldest  people.reduce((acc, person) > 
  person.age > acc.age ? person : acc
);

Extract a property from an array of objects

var names  [];for (var i  0; i < people.length; i++) {
  names.push(people[i].name);
}
const names  people.map(val > val.name);

Index an array of objects

var iPeople  {};for (var i  0; i < people.length; i++) {
  iPeople[people[i].id]  people[i];
}
const iPeople  people.reduce((acc, person) > {
  acc[person.id]  person;
  return acc;
}, {});

Find an element in array

var details  null;for (var i  0; i < people.length; i++) {
  if (people[i].name == 'Bob'){
    details  people[i];
    break;
  }
}
const details  people.find(val > val.name == 'Bob');

Summary

Subscribe for Email Updates:

Categories:

Tags:

Slides
Amdocs
Atlassian
Pomodoro Technique
Presentation
Agile Games
Kanban
Principles of Lean-Agile Leadership
Nexus and Kanban
agileisrael
AgileSparks
Agile for Embedded Systems
Sprint Iteration
Business Agility
LPM
ART Success
Kanban Basics
Managing Risk on Agile Projects
Scrum Master
NIT
Sprint Planning
BDD
predictability
Kaizen Workshop
RTE
Agile Contracts Best Practices
Team Flow
DevOps
Lean Agile
Lean Agile Organization
Artificial Intelligence
Acceptance Test-Driven Development
Continuous Deployment
Agile Basics
System Archetypes
Sprint Retrospectives
ScrumMaster Tales
Change Management
Agile Product Development
ALM Tools
Scrum With Kanban
Achieve Business Agility
The Kanban Method
ROI
Keith Sawyer
RSA
Jira Plans
SAFe DevOps
Agile Exercises
Agile Delivery
speed @ scale
Agile Release Planning
Legacy Enterprise
Coaching Agile Teams
Portfolio for Jira
GanttBan
Self-organization
Implementation of Lean and Agile
Webinar
Lean Agile Leadership
Story Slicing
Professional Scrum Product Owner
WIP
Agile
Nexus
Lean Startup
Lean-Agile Software Development
Built-In Quality
Agile Outsourcing
Tips
Continuous Integration
User stories
Limiting Work in Progress
Certified SAFe
Daily Scrum
PI Planning
Nexus Integration Team
Atlaassian
SAFe
SPC
Agility
chatgpt
Lean Agile Basics
Agile Project Management
AI Artificial Intelligence
Software Development Estimation
Kanban Game
Risk-aware Product Development
Nexus and SAFe
Covid19
Agile Release Management
ATDD vs. BDD
Agile Product Ownership
Scrum Primer
Code
Agile Assembly Architecture
Agile Program
Agile and DevOps Journey
Scrum Master Role
System Team
Agile Community
Certification
Risk Management in Kanban
ATDD
Iterative Incremental Development
EOS®
Operational Value Stream
Jira
Lean Budgeting
Software Development
LeSS
Agile Games and Exercises
Scrum
Systems Thinking
Agile in the Enterprise
Introduction to ATDD
Release Train Engineer
Product Ownership
Hybrid Work
Process Improvement
Accelerate Value Delivery At Scale
Scrum.org
Agile Risk Management
Video
Agile Project
Continuous Delivery
Professional Scrum Master
Perfection Game
POPM
Releases Using Lean
Introduction to Test Driven Development
Advanced Roadmaps
Games and Exercises
Lean and Agile Techniques
PI Objectives
TDD
An Appreciative Retrospective
SA
Implementing SAFe
Test Driven Development
Manage Budget Creation
Kanban 101
AI
Lean and Agile Principles and Practices
Agile Development
Elastic Leadership
Quality Assurance
Continuous Improvement
Jira Cloud
Rapid RTC
Agile Testing Practices
Entrepreneurial Operating System®
IT Operations
Agile Mindset
What Is Kanban
Scrum Guide
Lean Agile Management
Lean-Agile Budgeting
Managing Projects
Program Increment
Kanban Kickstart Example
Development Value Streams
Tools
A Kanban System for Software Engineering
Planning
Product Management
SAFe Release Planning
Kaizen
Effective Agile Retrospectives
Nexus vs SAFe
System Integration Environments
speed at scale
Agile Marketing
Agile Techniques
Frameworks
Agile Israel Events
Lean Risk Management
RTE Role
Applying Agile Methodology
Jira admin
lean agile change management
Scaled Agile Framework
Lean Software Development
Professional Scrum with Kanban
Legacy Code
Value Streams
Large Scale Scrum
Enterprise DevOps
Reading List
Risk Management on Agile Projects
Spotify
QA
Engineering Practices
Scrum and XP
Scrum Values
Continuous Planning
LAB
Agile Israel
Agile India
The Agile Coach
AgileSparks
Logo
Enable registration in settings - general

Contact Us

Request for additional information and prices

AgileSparks Newsletter

Subscribe to our newsletter, and stay updated on the latest Agile news and events

This website uses Cookies to provide a better experience
Shopping cart