Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object.keys equivalent lodash method

Tags:

I am new to loadash, I am trying to learn good ways to manipulate java script object.

Is there a equivalent loadash method for :

Object.keys({ "tab1": "1" , tab2: "2"})[0]; Object.keys({ "tab1": "1" , tab2: "2"})[2]; 

to get list values?

And also if there are easy and good ways to use lodash and any articles that I can go through.

like image 335
user2936008 Avatar asked Feb 23 '16 00:02

user2936008


People also ask

How do I get the object key in Lodash?

The _. keys() method is used to return the list of all keys of the given object. Parameters: This method accepts a single parameter as mentioned above and described below: object: This parameter holds the object elements.

How do you compare objects in Lodash?

In Lodash, we can deeply compare two objects using the _. isEqual() method. This method will compare both values to determine if they are equivalent.

What are Lodash methods?

Lodash is a popular javascript based library which provides 200+ functions to facilitate web development. It provides helper functions like map, filter, invoke as well as function binding, javascript templating, deep equality checks, creating indexes and so on.


1 Answers

_.keys should do the trick.

_.keys(object)

Creates an array of the own enumerable property names of object.

Example:

console.log(_.keys({ "tab1": "1" , tab2: "2"}));  console.log(Object.keys({ "tab1": "1" , tab2: "2"}));    // Outputs:  // ["tab1", "tab2"]  // ["tab1", "tab2"]
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.5.1/lodash.js"></script>

Side-note:

Remember that the keys of an object are not necessarily ordered, and so they can come back in any order the host chooses.

like image 85
Alexander O'Mara Avatar answered Oct 18 '22 13:10

Alexander O'Mara