-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathentries.js
52 lines (41 loc) · 1.74 KB
/
entries.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
// TOPIC /////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Array Method: .entries()
//
// SYNTAX ////////////////////////////////////////////////////////////////////////////////////////////////////
//
// array.entries()
//
// SUMMARY ///////////////////////////////////////////////////////////////////////////////////////////////////
//
// • .entries() method returns an array iterator object with key/value pairs.
// • .entries() is an inbuilt function used to get a new array that contains key/value paris for each
// index of an array.
//
// EXAMPLES //////////////////////////////////////////////////////////////////////////////////////////////////
//
// EXAMPLE 1: Create an entries iterator object using Object.entries
// EXAMPLE 2: entires iterator using for-loop
//
// RESOURCES /////////////////////////////////////////////////////////////////////////////////////////////////
//
// https://www.w3schools.com/jsref/jsref_entries.asp -- entries w3school
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
// EXAMPLE 1: Create an entries iterator object using Object.entries
const array = ['alpha', 'beta', 'charlie', 'delta', 'echo', 'frank', 'gold'];
function createEntriesIterator() {
const myArray = Object.entries(array);
return myArray;
}
console.log(createEntriesIterator());
// EXAMPLE 2: entires iterator using for-loop
const array2 = ["apple", "banana", "carrot", "dates", "eggs"];
function createAnotherEntryIterator() {
let iterator = array2.entries();
for (let i of iterator) {
console.log(i);
}
}
console.log(createAnotherEntryIterator());