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