node.js - Slice specific keys in javascript object -


in rails, have special slice method keep in hash keys need. handy permit required keys in hash.

is there method in node.js?

in javascript there not such method, in libraries lodash there method called _.pick

var data = { a: 1, b: 2, c: 3 };  console.log(_.pick(data, 'a', 'c'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.js"></script>

you can install lodash via npm

npm install lodash --save 

and require project

var _ = require('lodash') // import methods // or import pick method // var pick = require('lodash/object/pick'); 

Comments

Popular posts from this blog

Capture and play voice with Asterisk ARI -

visual studio - Installing Packages through Nuget - "Central Directory corrupt" -

java - Why database contraints in HSQLDB are only checked during a commit when using transactions in Hibernate? -