Replies: 3 comments
-
Probably i will need to enhance mapDeep, right now it's possible to do with eachDeep, but i am out of my laptop, so i will be able to create an example only in some hours. |
Beta Was this translation helpful? Give feedback.
-
I hope I understood your criteria right: var data = { arr: ['a', 'b', { c: ['y', 'w', 'z'] }, 'd', 'e',[1,2,3],{more:{nested:{arrays:[[1,2,3],[4,5,6],[7,8,9]]}}}]};
_.eachDeep(data,(val, key, parent, context)=>{
if(_.isArray(val) && !_.some(val, _.isObject)){
parent[key] = val.join();
return false;
}
}); data: {
"arr": [
"a",
"b",
{
"c": "y,w,z"
},
"d",
"e",
"1,2,3",
{
"more": {
"nested": {
"arrays": [
"1,2,3",
"4,5,6",
"7,8,9"
]
}
}
}
]
} |
Beta Was this translation helpful? Give feedback.
-
And about topic question: "can mapDeep alter structure?" Let me know please, if my suggestion works for you. |
Beta Was this translation helpful? Give feedback.
-
I used deep map to integrate some object node with extra properties and deepMap works perfectly returning new value where I want. The structure of the mapped object remains the same.
Let's suppose I need to transform array of strings node in a leaf with those string concatenated altering the structure:
{ arr: ['a', 'b', { c: ['y', 'w', 'z'] }, 'd', 'e'] }
{ arr: ['a', 'b', { c: "ywz" }, 'd', 'e'] }
I was no able to do that with deepMap. Is it possible?
Beta Was this translation helpful? Give feedback.
All reactions