Posts Array 다루기
Post
Cancel

Array 다루기

배열 요소 추가/제거

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const jbAry1 = [ 'one', 'two', 'three' ];
jbAry1.push( 'four' );
document.write( '<p>' + jbAry1.join( ' / ' ) + '</p>' );

const jbAry2 = [ 'one', 'two', 'three' ];
jbAry2.pop();
document.write( '<p>' + jbAry2.join( ' / ' ) + '</p>' );

const jbAry3 = [ 'one', 'two', 'three' ];
jbAry3.unshift( 'zero' );
document.write( '<p>' + jbAry3.join( ' / ' ) + '</p>' );

const jbAry4 = [ 'one', 'two', 'three' ];
jbAry4.shift();
document.write( '<p>' + jbAry4.join( ' / ' ) + '</p>' );

Result

1
2
3
4
one / two / three / four
one / two
zero / one / two / three
two / three

배열 뒤집기

Code

1
2
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.reverse();
This post is licensed under CC BY 4.0 by the author.