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:

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