javascript - Lodash split object - Stack Overflow

how can i use lodash to split the following object into two arraysthe object is {"M":["A

how can i use lodash to split the following object into two arrays

the object is

{"M":
  [
   "Alpha",
   "Beta",
   "Zeta"],
 "F":
    [
     "Alpha",
     "Omega"
  ]}

I want it to be

var first =  [
   "Alpha",
   "Beta",
   "Zeta"] // contents of M

var second =   [
     "Alpha",
     "Omega"
  ] // contents of F

is that possible in lodash? and if not then how is it possible in vanillaJS

thanks

how can i use lodash to split the following object into two arrays

the object is

{"M":
  [
   "Alpha",
   "Beta",
   "Zeta"],
 "F":
    [
     "Alpha",
     "Omega"
  ]}

I want it to be

var first =  [
   "Alpha",
   "Beta",
   "Zeta"] // contents of M

var second =   [
     "Alpha",
     "Omega"
  ] // contents of F

is that possible in lodash? and if not then how is it possible in vanillaJS

thanks

Share Improve this question edited Jul 13, 2016 at 0:03 user3052526 asked Jul 12, 2016 at 13:04 user3052526user3052526 68310 silver badges25 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

You don't need Lodash for this. Just:

var first = theObject.M;
var second = theObject.F;

first and second will refer to the arrays in the object. If you want to copy them, then:

var first = theObject.M.slice();
var second = theObject.F.slice();

Just for reference, this can be done very easily in es6:

const { M: first, F: second } = theObject;

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745554946a4632763.html

相关推荐

  • javascript - Lodash split object - Stack Overflow

    how can i use lodash to split the following object into two arraysthe object is {"M":["A

    18小时前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信