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:

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