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:

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