Advertisement
Fahim_7861

object convert into unique key js

Mar 23rd, 2021
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. const _ = require("lodash");
  2.  
  3. // The source object
  4. var info = [
  5. { 'user': 'amit', 'age': 23 },
  6. { 'user': 'priya', 'age': 21 },
  7.  
  8. { 'user': 'priya', 'age': 25 },
  9. ];
  10.  
  11. // Using the _.mapKeys() method
  12. const newInfo=_.mapKeys(info,
  13. function(o) { return o.age; })
  14.  
  15.  
  16. console.log('info',newInfo["25"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement