Package Exports
- syncforeachloop
- syncforeachloop/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (syncforeachloop) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
syncForEach is a synchronous version of the forEach loop.
In the example below, each of the cities is printed on the screen.
Install
To install the package via npm, run the following code in the terminal:
$ npm i syncforeachloop
Usage
For JavaScript:
const {} = require('syncforeachloop');For TypeScript:
import 'syncforeachloop'Examples
var cities = ["Paris","İstanbul","Berlin"]; //Defined an array of cities.
//Each variable will be assigned to a single city variable.
cities.syncForEach(function (city,next_city,index,length) {
console.log(index); // Index will be written to the console.
console.log(length); //Array length (array element count) will be written to the console.
console.log(city); //Each city will be written on the console.
next_city(); //This function will skip to the next element.
});In the example below, shows the use of callbacks.
var cities = ["Paris","İstanbul","Berlin"]; // Defined an array of cities.
// Each variable will be assigned to a single city variable.
cities.syncForEach(function (city,next_city,index,length) {
console.log(index); // Index will be written to the console.
console.log(length); // Array length (array element count) will be written to the console.
console.log(city); // Each city will be written on the console.
next_city(); // This function will skip to the next element.
},() => { // Calling a callback function after elements in all arrays are complete.
console.log('Loop Ended');
});In the example below, shows the use of callbacks from outside.
function callback() {
console.log('hello');
}
var cities = ["Paris","İstanbul","Berlin"]; // Defined an array of cities.
cities.syncForEach(function (city,next_city,index,length) {
console.log(index);
console.log(length);
console.log(city);
next_city();
},callback); // It is possible to call a function from outside.