💻
javascript
  • 자바스크립트 시작하기
  • 자바스크립트 기초 문법
  • 변수
  • 배열
  • 객체
  • 연산자
  • 조건문
    • if문
    • if ~else문
    • 다중 if문
    • 중첩 if문
    • switch문
    • 삼항 연산자
  • 반복문
    • while문
    • do while문
    • for문
    • 중첩 for문
    • break문
    • continue문
  • 함수
    • 선언적 함수
    • 익명함수
    • 매개변수가 있는 함수
    • arguments 함수
    • 리턴값이 있는 함수
    • 재귀함수
    • 콜백함수
    • 내부함수(스코프)
    • 객체 생성자 함수
    • 프로토타입 함수
    • 화살표 함수
    • 클래스
    • Promise
    • 템플릿 리터럴
  • 내장객체
    • String 객체
      • split()
      • join()
    • Number 객체
    • Date 객체
    • Array 객체
    • Math 객체
    • 정규표현 객체
  • 브라우저 객체
    • window 객체
    • navigator 객체
    • screen 객체
    • history 객체
    • location 객체
  • 문서객체
  • 이벤트
Powered by GitBook
On this page
  • 102페이지 예제
  • 103페이지 예제

Was this helpful?

  1. 내장객체

Array 객체

메서드

설명

join()

배열 사이에 지정된 문자열을 추가하기

reverse()

배열을 역순으로 정렬하기

sort()

배열 정렬하기

slice()

배열을 일부 선택하기

concat()

배열을 합치기

shift()

첫 번째 배열 가져오기 또는 제거하기

unshift()

첫 번째 배열 추가하기

pop()

마지막 배열 제거하기

//Array 객체
const arr10 = [100, 200, 300, 400, 500];
const arr20 = [600, 700, 800, 900, 1000];

document.write(arr10, "<br>");
document.write(arr10.join('*'), "<br>");
document.write(arr10.reverse(), "<br>");
document.write(arr10.sort(), "<br>");
document.write(arr10.sort(function(a, b){return b - a}), "<br>");
document.write(arr10.sort(function(a, b){return a - b}), "<br>");
document.write(arr10.slice(1, 3), "<br>");
document.write(arr10.slice(2, 3), "<br>");
document.write(arr10.concat(arr20), "<br>");
document.write(arr10.shift(), "<br>");  //첫번째 값 가져오기 
document.write(arr10, "<br>");  //shift로 인해 100은 잘리고 200부터
document.write(arr10.unshift(100), "<br>");
document.write(arr10, "<br>");
document.write(arr10.pop(), "<br>");
document.write(arr10, "<br>");

//100,200,300,400,500
//100*200*300*400*500
//500,400,300,200,100
//100,200,300,400,500
//500,400,300,200,100
//100,200,300,400,500
//200,300
//300
//100,200,300,400,500,600,700,800,900,1000
//100
//200,300,400,500
//5
//100,200,300,400,500
//500
//100,200,300,400

102페이지 예제

<script>
    let arr_1 = ["사당", "교대", "방배", "강남"];
    let arr_2 = ["신사", "압구정", "옥수"];
    
    let result = arr_1.join("-");
    console.log(result);
    
    let result = arr_1.concat(arr_2);
    console.log(result);
    
    let result = arr_1.slice(1,3);
    console.log(result);
    
    arr_1.sort();
    console.log(arr_1);
    
    arr_2.reverse();
    console.log(arr_2);
</script>

103페이지 예제

<script>
    let greenArr = ["교대", "방배", "강남"];
    let yellowArr = ["미금", "정자", "수서"];
    
    greenArr.splice(2, 1, "서초", "역삼");
    console.log(greenArr);
    
    let data1 = yellowArr.pop();
    let data2 = yellowArr.shift();
    
    yellowArr.push(data2);
    console.log(yellowArr);
    
    yellowArr.unshift(data1);
    console.log(yellowArr);
</script>

PreviousDate 객체NextMath 객체

Last updated 4 years ago

Was this helpful?