Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

for of mdn

let array = [10, 20, 30];

for (let valore of array) {
  console.log(valore);
}
// Output:
// 10
// 20
// 30
Comment

for of mdn

function* fibonacci() { // generatore di funzione
  let [prev, curr] = [0, 1];
  while (true) {
    [prev, curr] = [curr, prev + curr];
    yield curr;
  }
}

for (let n of fibonacci()) {
  console.log(n);
  // tronca la sequenza a 1000
  if (n >= 1000) {
    break;
  }
}
Comment

for of mdn

let iterable = [10, 20, 30];

for (const value of iterable) {
  console.log(value); // il valore di value di questo ciclo rimarrà costante
  value++; // operazione non consentita.
}
// 10
// 20
// 30
Comment

for of mdn

let iterable = "boo";

for (let value of iterable) {
  console.log(value);
}
// output:
// "b"
// "o"
// "o"
Comment

for of mdn

let iterable = new Uint8Array([0x00, 0xff]);

for (let value of iterable) {
  console.log(value);
}
// 0
// 255
Comment

for of mdn

let iterable = new Set([1, 1, 2, 2, 3, 3]);

for (let value of iterable) {
  console.log(value);
}
// 1
// 2
// 3
Comment

for of mdn

Object.prototype.objCustom = function () {};
Array.prototype.arrCustom = function () {};

let iterable = [3, 5, 7];
iterable.foo = "hello";

for (let i in iterable) {
  console.log(i); // logs 0, 1, 2, "foo", "arrCustom", "objCustom"
}

for (let i of iterable) {
  console.log(i); // logs 3, 5, 7
}
Comment

mdn for..of

function* fibonacci() { // a generator function
  let [prev, curr] = [0, 1];
  while (true) {
    [prev, curr] = [curr, prev + curr];
    yield curr;
  }
}

for (const n of fibonacci()) {
  console.log(n);
  // truncate the sequence at 1000
  if (n >= 1000) {
    break;
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: add id to Array of Object 
Javascript :: what is the difference between let and const in javascript 
Javascript :: how to allow implicit any in .d.ts 
Javascript :: is undefined false in javascript 
Javascript :: pdf to json online 
Javascript :: javascript for loop array of objects 
Javascript :: get url of website javascript 
Javascript :: disable long press on chrome 
Javascript :: Connect to socket.io node.js command line 
Javascript :: submit form without redirection 
Javascript :: prevent duplicate entries in javascript array 
Javascript :: access mouse position javascript 
Javascript :: Missing script: "start" react 
Javascript :: react pass props to children 
Javascript :: How to make HTML input tag only accept numerical values? in jsx 
Javascript :: Get element by ID with only a partial string 
Javascript :: handle onchange react 
Javascript :: react native nav bars 
Javascript :: axios post request javascript 
Javascript :: set selected value of dropdown using formcontrol in angular 
Javascript :: how to enable emit on react in vs code 
Javascript :: javascript array slice 
Javascript :: JSON parse error: Cannot deserialize value of type `java.time.LocalDateTime` from String 
Javascript :: mongo connect npm 
Javascript :: How To Take Screenshots In The Browser Using JavaScript 
Javascript :: json.stringify pretty 
Javascript :: accessing objects inside array 
Javascript :: check if string is empty 
Javascript :: mongodb mongoose with next js connection 
Javascript :: jsjs trigger window error 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =