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:

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