졸업작품_preparing..../node_js
npm 모듈 사용법
IT grow.
2019. 1. 30. 15:15
반응형
이번에는 underscore 라는 모듈을 사용해 볼 것이다 .
모듈 사용에 앞서 ,
npm init
을 해줌으로써 초기화를 시켜 준다 .
그리고 나서 우리가 사용해볼 , underscore 을 다운받아 준다 .
이 때 , 다운방법 2가지가 있다 .
npm install underscore
npm install underscore --save
2가지 차이점은 정확히 모르겠지만 , --save를 해줘야 한다 .
이제 이 모듈을 코드를 통해서 어떻게 사용되는지 알아 본다 .
underscore.js
var _ = require('underscore');
var arr = [1,2,3,4,5];
console.log(arr[0]);
console.log(_.first(arr));
console.log(arr[arr.length-1]);
console.log(_.last(arr));
결과 값은 각각
1
1
5
5
위처럼 뜨게 된다 .
underscore은 배열을 도와주는 모듈인 것 같다 .
반응형