showing results for - "spread"
Yannick
25 Jun 2019
1const list = ['Potato', 'Apple', 'Baguette', 'Elon Musk'];
2console.log(...list); // <- Triple hyphen is what we call a spread
3
4// Output : Potato Apple Baguette Elon Musk
5
6
7
8
9
10
11// ---- Expand for more detailed description ---- //
12
13// Spread syntax (...) allows an iterable such as an array expression
14// or string to be expanded in places where zero or more arguments
15// (for function calls) or elements (for array literals) are expected,
16// or an object expression to be expanded in places where zero or more
17// key-value pairs (for object literals) are expected.
18
19// Spread syntax can be used when all elements from an object or array
20// need to be included in a list of some kind.
21
22// | Mozilla doc in source just below
23// v
Alia
11 Sep 2017
1const rgb = [255, 0, 0];
2
3// Randomly change to showcase updates
4setInterval(setContrast, 1000);
5
6function setContrast() {
7  // Randomly update colours
8  rgb[0] = Math.round(Math.random() * 255);
9  rgb[1] = Math.round(Math.random() * 255);
10  rgb[2] = Math.round(Math.random() * 255);
11
12  // http://www.w3.org/TR/AERT#color-contrast
13  const brightness = Math.round(((parseInt(rgb[0]) * 299) +
14                      (parseInt(rgb[1]) * 587) +
15                      (parseInt(rgb[2]) * 114)) / 1000);
16  const textColour = (brightness > 125) ? 'black' : 'white';
17  const backgroundColour = 'rgb(' + rgb[0] + ',' + rgb[1] + ',' + rgb[2] + ')';
18  $('#bg').css('color', textColour); 
19  $('#bg').css('background-color', backgroundColour);
20}
queries leading to this page
javascript loop through objectfor loop over object javascriptwhich method do we use to loop an object jsfor loop object comes out as 5bobject object 5dshould i create object inside for looploop through javascript objectloop through object values javascriptfor in loop object javascriptreturn object in for loophow can i interate through a objecti in jsloop over an object javascriptcan i loop a object property in javscriptlooping methods for objects javascript javascript iterate over objectjs loop through objectsloop over objecthow to create object in javascript with looploop an object in javascriptlooping objects javascriptfor in loop for objectshow to loops objectsloop through object using forloop object javascriptfor loop to iterate through object javascriptloop over objectsiterate over object javascriptloops not available for object jshow to iterate throught an object in javascriptjavascript object looplooping object javascriptjavascript for loop objectiterate through an object javascripthow to loop in this object 5b 7b e2 80 a6 7d 5dinside object loopaccess value of object javascript in for loop how to etrate loop in objecthow to loop over object in javascriptloop an objectjavascript cycle through object spreadfor of iteration in objectwhich method do we use to loop an object 3fjavascript object loopsjs loop objecthow to loop in objectsname of object with loop forloop over object javascriptslatesjs change text colorhow to loop over object values in javascriptloop through object entriesloop through objectloop on object jsfor loop in javascript for objectspreadjs loop through objecthow to loop through an object in javascriptloop object valuesjs loop over value of objectdisplay object loopjavascript loop over objectiterate over object jsloop in object javascriptfor of method used to loop an object 3fobject for loop javascripthow to loop through object in javascriptloop through js objectiterate through an objectloop torugh objectiterating over objectloop to object javascriptjavascript get text color from backgroundfor loop storing in new objectloop method in objectloop object javascriptfor loop on objectloop object for inloop through object javascriptjavascript change text color based on backgroundhow to go through the elements of an object and create a new objectspread