본문 바로가기
TIL/Learn - JavaScript

for in & for of & forEach

by koreashowme 2019. 9. 24.

var data = [1, 2, undefined, NaN, null, ""];

data.forEach(function(value){

console.log("value is", value);

});

 

var data = [1, 2, undefined, NaN, null, ""];

for(let idx in data){

 console.log(data[idx]);

}

 

console

====>

1

2

undefined

NaN

null

""

 

=======================================================

 

var data = [1, 2, undefined, NaN, null, ""];

Array.prototype.getIndex = function() {}

for(let idx in data){

 console.log(data[idx]);

}

 

 

console

====>

1

2

undefined

NaN

null

""

function() {}

 

 

 

var data = [1, 2, undefined, NaN, null, ""];

Array.prototype.getIndex = function() {}

for(let value of data){

     console.log(value);

}

 

console

====>

1

2

undefined

NaN

null

""

============================

var str= "hello world!!!"

Array.prototype.getIndex = function() {}

for(let value of str){     

console.log(value);

}

console

====>

h

e

l

l

o

 

w

o

r

l

d

!

!

!

 

 

 

 

 

'TIL > Learn - JavaScript' 카테고리의 다른 글

filter, inclues, from 예제  (0) 2019.09.24
spread operator  (0) 2019.09.24
자바스크립트 list.push & concat  (0) 2019.09.23
Ajax란?  (0) 2019.09.18
window.onload  (0) 2019.08.30

comment