Object.keys Equivalent Lodash Method
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.
Solution 1:
_.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"]
<scriptsrc="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.
Post a Comment for "Object.keys Equivalent Lodash Method"