⊗jsSpMdIN 217 of 294 menu

npm modules import in JavaScript

You can include not only your own modules, but also modules installed via npm. At the same time, for your modules, you need to specify ./ before, but for npm modules, you don’t need it.

Let's look at an example. We will install the underscore library:

npm install underscore

And include it:

import _ from 'underscore';

Let's use some functions of the imorted library:

import _ from 'underscore'; let arr = [1, 2, 3, 4, 5] let res = _.first(arr) + _.last(arr); console.log(res);

You can import not all functions, but only the necessary ones:

import {first, last} from 'underscore'; let arr = [1, 2, 3, 4, 5] let res = first(arr) + last(arr); console.log(res);

Install the lodash library. Include it to your project and use several methods from this library.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline