Skip to content
/ getFirst Public

Javascript utility to get the first item of object or array.

Notifications You must be signed in to change notification settings

mpeix/getFirst

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jsgetfirst

Build Status

Use this package to get the first element of an array or object

Installation

To install the package run: npm install jsgetfirst --save

How to use it?

To get it in you project, call it in you file and use it directly.

//Calling jsgetfirst package
const {getfirst} = require('jsgetfirst');

Get first item of an array

//Calling jsgetfirst package
const {getfirst} = require('jsgetfirst');

//Array to get first item
const arrayList = ["50", "25", "100"];

//Use getfirst in your code
const getFirstExample  = () => {
    return getfirst(arrayList);
}

In the previous example you will get "50" as a result of getFirstExample call.

Get first item of an object

Proceed as the above example:

//Calling jsgetfirst package
const {getfirst} = require('jsgetfirst');

//Object to get first item
const testObject = {
    car : {
        wheels : 4,
        doors : 3,
        power: 25
    },
    truk : {
        wheels : 12,
        doors : 2,
        power: 125 
    },
    bus : {
        wheels : 12,
        doors : 5,
        power: 100
    }
}

//Use getfirst in your code
const getFirstExample  = () => {
    return getfirst(testObject);
}

Here the result obtined will be:

{ 
    car: { 
        wheels: 4, 
        doors: 3, 
        power: 25 
    } 
}

About

Javascript utility to get the first item of object or array.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published