배열 만드는 방법
1. []로 만들기
var week=['월','화','수','목','금','토','일'];
2. Array로 만들기
var week = new Array('월','화','수','목');
var week=new Array();
배열 특징
- Array 객체
- 여러 타입의 데이터가 섞여 저장 가능
var any=new Array();
any[0]=0;
any[1]=5.5;
any[2]='가나다라마바사';
Array 객체 메소드
var a= new Array('가나다');
var b=new Array('라');
var c;
c=a.concat(b);
c=a.join('##');
c=a.reverse();
c=a.slice(1,2);
c=a.sort();
c=a.toString();
String
var hello='hello'
var hello= new String('hello')
- 문자열은 String 생략 가능
사용자 객체 만들기
//account 이름의 객체를 만들고 프로퍼티를 추가
var account=new Object();
account.owner='황기태';
account.code='111';
account.balance='35000';
사용자 객체에 메소드 만들기
function deposit(money){
this.balance+=money;
}
account.deposit=deposit;
account.deposit(1000);
프로토타입으로 객체 만들기
function Account(owner,code,balance){
this.owner=owner;
this.code=code;
this.balance=balance;
this.inquiry=function(){return this.balance;}
this.deposit=function(money){this.balance+=balance;}
this.withdraw=function(money){
this.balance-=money;
return money;}
}
// 객체 활용
var account=new Account('황기태','111',35000);
account.deposit(10000);
반응형
'FrontEnd' 카테고리의 다른 글
[자바스크립트] 자바스크립트 언어 특징 및 문법 (0) | 2023.04.23 |
---|---|
[CSS3] CSS3로 웹 페이지 꾸미기 (0) | 2023.04.22 |
[HTML5] HTML5 문서 구조화 (0) | 2023.04.20 |
[HTML5] HTML5 기본 문서 만들기 (0) | 2023.04.20 |
웹 프로그래밍 개요 (0) | 2023.04.18 |
댓글