[JS] Array.prototype.forEach()

Captainjack·2021년 4월 15일
0

TIL

목록 보기
200/260

Array.prototype.forEach()

The forEach() method executes a provided function once for each array element.


const array1 = ['a', 'b', 'c'];

array1.forEach(element => console.log(element));

// expected output: "a"
// expected output: "b"
// expected output: "c"
// from mdn

return value => boolean

for example for understanding me

doubleSrr.forEach((edge) => {
  		//forEach bring a Array elements
  		//it's like for repeat +Each choice in Array
  		//Automatically search all of the Array contents.
		const [row, col, direction] = edge;
  		// save edge in [row, col, direction]
		if (direction === "undirected") {
          //it's freaking crazy code
          //it's control two case at the same time
			result[col][row] = 1;
          
		}
		result[row][col] = 1;
	});

for(let i=0; i<somearr. length; i++){
	max = Math.max(...doubleArr[i].slice(0,2)); //doublearr = [[]]
   //Math.max is return a MAX value "1", "2" each in the case in [1,1, blah blah],[0,2, blah blah]
   // ...doublearr is cover off the arr like the [[]]-> []
  // and this result is just reutn a Number type number like 1, 2 (number)
}

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach

profile
til' CTF WIN

0개의 댓글