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 badges2 Answers
Reset to default 3You 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;