Friday, January 6, 2023

JavaScript Loops

 // Looping Stmts

for(let i = 0; i < 10; i++) {
	console.log(i);
}

// Looping Array 
const myArray = [
	'Srinu', 
	'SFDC', 
	34, 
	['Admin','PD1'], 
	'Salesforce Architect'
];
const indexes = [];

for(let i = 0; i < myArray.length; i++) {
	console.log(myArray[i], i);
	// indexes[i] = i;
	indexes.push(i);
}
console.log(indexes);

// Using continue 
for(let i = 0; i < myArray.length; i++) {
	if(typeof myArray[i] !== 'string') continue;
	console.log(myArray[i], i);
}

// Using break 
for(let i = 0; i < myArray.length; i++) {
	if(typeof myArray[i] === 'string') break;
	console.log(myArray[i], i);
}

// while loop

No comments:

Post a Comment

Understanding Wire vs Imperative Apex Method Calls in Salesforce Lightning Web Components (LWC)

Understanding Wire vs Imperative Apex Method Calls in Salesforce Lightning Web Components (LWC) Introduction: Salesforce Lightning Web ...