How do I remove an object if it contains a key with an empty array?How to check empty/undefined/null string in JavaScript?How do I remove a property from a JavaScript object?How do I check if an array includes an object in JavaScript?How to append something to an array?How do I test for an empty JavaScript object?Checking if a key exists in a JavaScript object?How do I empty an array in JavaScript?How to check whether a string contains a substring in JavaScript?How to check if an object is an array?How do I remove a particular element from an array in JavaScript?
Applied Meditation
Word for pulling a punch in karate
How to set Adobe DC PDF reader as default for ALL pdfs without having to open security preferences every time
Adding a (stair/baby) gate without facing walls
What is realistic quality of computer blueprints quickly backed up before apocalypse and their impact on future design?
Pre-Greek θάλασσα "thalassa" and Turkish talaz
Being told my "network" isn't PCI Complaint. I don't even have a server! Do I have to comply?
Gold Battle KoTH
Can I say "Gesundheit" if someone is coughing?
Could flaps be raised upward to serve as spoilers / lift dumpers?
"Will flex for food". What does this phrase mean?
Is it moral to remove/hide certain parts of a photo, as a photographer?
Skipping same old introductions
Is it really a problem to declare that a visitor to the UK is my "girlfriend", in terms of her successfully getting a Standard Visitor visa?
How does Asimov's second law deal with contradictory orders from different people?
Does the use of a new concept require a prior definition?
Is the EU really banning "toxic propellants" in 2020? How is that going to work?
Traveling from New York city to Starkville Mississippi with public transport
How do people drown while wearing a life jacket?
Why are sugars in whole fruits not digested the same way sugars in juice are?
Backpacking with incontinence
When did J.K. Rowling decide to make Ron and Hermione a couple?
What do the screens say after you are set free?
Can an alphabet for a Turing machine contain subsets of other alphabets?
How do I remove an object if it contains a key with an empty array?
How to check empty/undefined/null string in JavaScript?How do I remove a property from a JavaScript object?How do I check if an array includes an object in JavaScript?How to append something to an array?How do I test for an empty JavaScript object?Checking if a key exists in a JavaScript object?How do I empty an array in JavaScript?How to check whether a string contains a substring in JavaScript?How to check if an object is an array?How do I remove a particular element from an array in JavaScript?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have an an array of objects. My objective is to remove objects that contain keys with empty arrays.
I am using ramda, but am hitting a wall at the moment.
const myData =
"one":
"two":
"id": "1",
"three": [
"id": "33",
"copy": [
"id": "1",
"text": "lorem",
"answer": [],
,
"id": "2",
"text": "ipsum",
"answer": [
"id": 1,
"class": "science"
]
,
"id": "3",
"text": "baesun",
"answer": [
"id": 2,
"class": "reading"
]
],
]
flatten(pipe(
path(['one', 'two', 'three']),
map(step => step.copy.map(text => (
answers: text.answer.map(answer => (
class: answer.class,
)),
), ), ))
(myData))
This the result:
["answers": [], "answers": ["class": "science"], "answers": ["class": "reading"]]
This is the expectation:
["answers": ["class": "science"], "answers": ["class": "reading"]]
javascript ramda.js
add a comment |
I have an an array of objects. My objective is to remove objects that contain keys with empty arrays.
I am using ramda, but am hitting a wall at the moment.
const myData =
"one":
"two":
"id": "1",
"three": [
"id": "33",
"copy": [
"id": "1",
"text": "lorem",
"answer": [],
,
"id": "2",
"text": "ipsum",
"answer": [
"id": 1,
"class": "science"
]
,
"id": "3",
"text": "baesun",
"answer": [
"id": 2,
"class": "reading"
]
],
]
flatten(pipe(
path(['one', 'two', 'three']),
map(step => step.copy.map(text => (
answers: text.answer.map(answer => (
class: answer.class,
)),
), ), ))
(myData))
This the result:
["answers": [], "answers": ["class": "science"], "answers": ["class": "reading"]]
This is the expectation:
["answers": ["class": "science"], "answers": ["class": "reading"]]
javascript ramda.js
add a comment |
I have an an array of objects. My objective is to remove objects that contain keys with empty arrays.
I am using ramda, but am hitting a wall at the moment.
const myData =
"one":
"two":
"id": "1",
"three": [
"id": "33",
"copy": [
"id": "1",
"text": "lorem",
"answer": [],
,
"id": "2",
"text": "ipsum",
"answer": [
"id": 1,
"class": "science"
]
,
"id": "3",
"text": "baesun",
"answer": [
"id": 2,
"class": "reading"
]
],
]
flatten(pipe(
path(['one', 'two', 'three']),
map(step => step.copy.map(text => (
answers: text.answer.map(answer => (
class: answer.class,
)),
), ), ))
(myData))
This the result:
["answers": [], "answers": ["class": "science"], "answers": ["class": "reading"]]
This is the expectation:
["answers": ["class": "science"], "answers": ["class": "reading"]]
javascript ramda.js
I have an an array of objects. My objective is to remove objects that contain keys with empty arrays.
I am using ramda, but am hitting a wall at the moment.
const myData =
"one":
"two":
"id": "1",
"three": [
"id": "33",
"copy": [
"id": "1",
"text": "lorem",
"answer": [],
,
"id": "2",
"text": "ipsum",
"answer": [
"id": 1,
"class": "science"
]
,
"id": "3",
"text": "baesun",
"answer": [
"id": 2,
"class": "reading"
]
],
]
flatten(pipe(
path(['one', 'two', 'three']),
map(step => step.copy.map(text => (
answers: text.answer.map(answer => (
class: answer.class,
)),
), ), ))
(myData))
This the result:
["answers": [], "answers": ["class": "science"], "answers": ["class": "reading"]]
This is the expectation:
["answers": ["class": "science"], "answers": ["class": "reading"]]
javascript ramda.js
javascript ramda.js
edited Mar 27 at 0:27
Ele
26.8k6 gold badges24 silver badges54 bronze badges
26.8k6 gold badges24 silver badges54 bronze badges
asked Mar 27 at 0:25
samrumlinsamrumlin
1
1
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Get the the array of inside three
with path, chain the arrays inside the copy
properties, and project them to contain only answer
. Reject empty answers, and then evolve the objects inside each answer to contain only the class
property.
const pipe, path, chain, prop, project, reject, propSatisfies, isEmpty, map, evolve = ramda
const transform = pipe(
path(['one', 'two', 'three']), // get the array
chain(prop('copy')), // concat the copy to a single array
project(['answer']), // extract the answers
reject(propSatisfies(isEmpty, 'answer')), // remove empty answers
map(evolve( answer: project(['class']) )) // convert the objects inside each answer to contain only class
)
const data = "one":"two":"id":"1","three":["id":"33","copy":["id":"1","text":"lorem","answer":[],"id":"2","text":"ipsum","answer":["id":1,"class":"science"],"id":"3","text":"baesun","answer":["id":2,"class":"reading"]]]
const result = transform(data)
console.log(result)
<script src="//bundle.run/ramda@0.26.1"></script>
add a comment |
use filter
const filter = R.filter,
flatten = R.flatten,
pipe = R.pipe,
path = R.path,
map = R.map;
const myData =
"one":
"two":
"id": "1",
"three": [
"id": "33",
"copy": [
"id": "1",
"text": "lorem",
"answer": [],
,
"id": "2",
"text": "ipsum",
"answer": [
"id": 1,
"class": "science"
]
,
"id": "3",
"text": "baesun",
"answer": [
"id": 2,
"class": "reading"
]
],
]
const result = filter(answersObj => answersObj.answers.length, flatten(pipe(
path(['one', 'two', 'three']),
map(step => step.copy.map(text => (
answers: text.answer.map(answer => (
class: answer.class,
))
)))
)(myData)))
console.log(result);
<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55368068%2fhow-do-i-remove-an-object-if-it-contains-a-key-with-an-empty-array%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Get the the array of inside three
with path, chain the arrays inside the copy
properties, and project them to contain only answer
. Reject empty answers, and then evolve the objects inside each answer to contain only the class
property.
const pipe, path, chain, prop, project, reject, propSatisfies, isEmpty, map, evolve = ramda
const transform = pipe(
path(['one', 'two', 'three']), // get the array
chain(prop('copy')), // concat the copy to a single array
project(['answer']), // extract the answers
reject(propSatisfies(isEmpty, 'answer')), // remove empty answers
map(evolve( answer: project(['class']) )) // convert the objects inside each answer to contain only class
)
const data = "one":"two":"id":"1","three":["id":"33","copy":["id":"1","text":"lorem","answer":[],"id":"2","text":"ipsum","answer":["id":1,"class":"science"],"id":"3","text":"baesun","answer":["id":2,"class":"reading"]]]
const result = transform(data)
console.log(result)
<script src="//bundle.run/ramda@0.26.1"></script>
add a comment |
Get the the array of inside three
with path, chain the arrays inside the copy
properties, and project them to contain only answer
. Reject empty answers, and then evolve the objects inside each answer to contain only the class
property.
const pipe, path, chain, prop, project, reject, propSatisfies, isEmpty, map, evolve = ramda
const transform = pipe(
path(['one', 'two', 'three']), // get the array
chain(prop('copy')), // concat the copy to a single array
project(['answer']), // extract the answers
reject(propSatisfies(isEmpty, 'answer')), // remove empty answers
map(evolve( answer: project(['class']) )) // convert the objects inside each answer to contain only class
)
const data = "one":"two":"id":"1","three":["id":"33","copy":["id":"1","text":"lorem","answer":[],"id":"2","text":"ipsum","answer":["id":1,"class":"science"],"id":"3","text":"baesun","answer":["id":2,"class":"reading"]]]
const result = transform(data)
console.log(result)
<script src="//bundle.run/ramda@0.26.1"></script>
add a comment |
Get the the array of inside three
with path, chain the arrays inside the copy
properties, and project them to contain only answer
. Reject empty answers, and then evolve the objects inside each answer to contain only the class
property.
const pipe, path, chain, prop, project, reject, propSatisfies, isEmpty, map, evolve = ramda
const transform = pipe(
path(['one', 'two', 'three']), // get the array
chain(prop('copy')), // concat the copy to a single array
project(['answer']), // extract the answers
reject(propSatisfies(isEmpty, 'answer')), // remove empty answers
map(evolve( answer: project(['class']) )) // convert the objects inside each answer to contain only class
)
const data = "one":"two":"id":"1","three":["id":"33","copy":["id":"1","text":"lorem","answer":[],"id":"2","text":"ipsum","answer":["id":1,"class":"science"],"id":"3","text":"baesun","answer":["id":2,"class":"reading"]]]
const result = transform(data)
console.log(result)
<script src="//bundle.run/ramda@0.26.1"></script>
Get the the array of inside three
with path, chain the arrays inside the copy
properties, and project them to contain only answer
. Reject empty answers, and then evolve the objects inside each answer to contain only the class
property.
const pipe, path, chain, prop, project, reject, propSatisfies, isEmpty, map, evolve = ramda
const transform = pipe(
path(['one', 'two', 'three']), // get the array
chain(prop('copy')), // concat the copy to a single array
project(['answer']), // extract the answers
reject(propSatisfies(isEmpty, 'answer')), // remove empty answers
map(evolve( answer: project(['class']) )) // convert the objects inside each answer to contain only class
)
const data = "one":"two":"id":"1","three":["id":"33","copy":["id":"1","text":"lorem","answer":[],"id":"2","text":"ipsum","answer":["id":1,"class":"science"],"id":"3","text":"baesun","answer":["id":2,"class":"reading"]]]
const result = transform(data)
console.log(result)
<script src="//bundle.run/ramda@0.26.1"></script>
const pipe, path, chain, prop, project, reject, propSatisfies, isEmpty, map, evolve = ramda
const transform = pipe(
path(['one', 'two', 'three']), // get the array
chain(prop('copy')), // concat the copy to a single array
project(['answer']), // extract the answers
reject(propSatisfies(isEmpty, 'answer')), // remove empty answers
map(evolve( answer: project(['class']) )) // convert the objects inside each answer to contain only class
)
const data = "one":"two":"id":"1","three":["id":"33","copy":["id":"1","text":"lorem","answer":[],"id":"2","text":"ipsum","answer":["id":1,"class":"science"],"id":"3","text":"baesun","answer":["id":2,"class":"reading"]]]
const result = transform(data)
console.log(result)
<script src="//bundle.run/ramda@0.26.1"></script>
const pipe, path, chain, prop, project, reject, propSatisfies, isEmpty, map, evolve = ramda
const transform = pipe(
path(['one', 'two', 'three']), // get the array
chain(prop('copy')), // concat the copy to a single array
project(['answer']), // extract the answers
reject(propSatisfies(isEmpty, 'answer')), // remove empty answers
map(evolve( answer: project(['class']) )) // convert the objects inside each answer to contain only class
)
const data = "one":"two":"id":"1","three":["id":"33","copy":["id":"1","text":"lorem","answer":[],"id":"2","text":"ipsum","answer":["id":1,"class":"science"],"id":"3","text":"baesun","answer":["id":2,"class":"reading"]]]
const result = transform(data)
console.log(result)
<script src="//bundle.run/ramda@0.26.1"></script>
edited Mar 27 at 9:11
answered Mar 27 at 8:12
Ori DroriOri Drori
91.6k15 gold badges104 silver badges109 bronze badges
91.6k15 gold badges104 silver badges109 bronze badges
add a comment |
add a comment |
use filter
const filter = R.filter,
flatten = R.flatten,
pipe = R.pipe,
path = R.path,
map = R.map;
const myData =
"one":
"two":
"id": "1",
"three": [
"id": "33",
"copy": [
"id": "1",
"text": "lorem",
"answer": [],
,
"id": "2",
"text": "ipsum",
"answer": [
"id": 1,
"class": "science"
]
,
"id": "3",
"text": "baesun",
"answer": [
"id": 2,
"class": "reading"
]
],
]
const result = filter(answersObj => answersObj.answers.length, flatten(pipe(
path(['one', 'two', 'three']),
map(step => step.copy.map(text => (
answers: text.answer.map(answer => (
class: answer.class,
))
)))
)(myData)))
console.log(result);
<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script>
add a comment |
use filter
const filter = R.filter,
flatten = R.flatten,
pipe = R.pipe,
path = R.path,
map = R.map;
const myData =
"one":
"two":
"id": "1",
"three": [
"id": "33",
"copy": [
"id": "1",
"text": "lorem",
"answer": [],
,
"id": "2",
"text": "ipsum",
"answer": [
"id": 1,
"class": "science"
]
,
"id": "3",
"text": "baesun",
"answer": [
"id": 2,
"class": "reading"
]
],
]
const result = filter(answersObj => answersObj.answers.length, flatten(pipe(
path(['one', 'two', 'three']),
map(step => step.copy.map(text => (
answers: text.answer.map(answer => (
class: answer.class,
))
)))
)(myData)))
console.log(result);
<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script>
add a comment |
use filter
const filter = R.filter,
flatten = R.flatten,
pipe = R.pipe,
path = R.path,
map = R.map;
const myData =
"one":
"two":
"id": "1",
"three": [
"id": "33",
"copy": [
"id": "1",
"text": "lorem",
"answer": [],
,
"id": "2",
"text": "ipsum",
"answer": [
"id": 1,
"class": "science"
]
,
"id": "3",
"text": "baesun",
"answer": [
"id": 2,
"class": "reading"
]
],
]
const result = filter(answersObj => answersObj.answers.length, flatten(pipe(
path(['one', 'two', 'three']),
map(step => step.copy.map(text => (
answers: text.answer.map(answer => (
class: answer.class,
))
)))
)(myData)))
console.log(result);
<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script>
use filter
const filter = R.filter,
flatten = R.flatten,
pipe = R.pipe,
path = R.path,
map = R.map;
const myData =
"one":
"two":
"id": "1",
"three": [
"id": "33",
"copy": [
"id": "1",
"text": "lorem",
"answer": [],
,
"id": "2",
"text": "ipsum",
"answer": [
"id": 1,
"class": "science"
]
,
"id": "3",
"text": "baesun",
"answer": [
"id": 2,
"class": "reading"
]
],
]
const result = filter(answersObj => answersObj.answers.length, flatten(pipe(
path(['one', 'two', 'three']),
map(step => step.copy.map(text => (
answers: text.answer.map(answer => (
class: answer.class,
))
)))
)(myData)))
console.log(result);
<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script>
const filter = R.filter,
flatten = R.flatten,
pipe = R.pipe,
path = R.path,
map = R.map;
const myData =
"one":
"two":
"id": "1",
"three": [
"id": "33",
"copy": [
"id": "1",
"text": "lorem",
"answer": [],
,
"id": "2",
"text": "ipsum",
"answer": [
"id": 1,
"class": "science"
]
,
"id": "3",
"text": "baesun",
"answer": [
"id": 2,
"class": "reading"
]
],
]
const result = filter(answersObj => answersObj.answers.length, flatten(pipe(
path(['one', 'two', 'three']),
map(step => step.copy.map(text => (
answers: text.answer.map(answer => (
class: answer.class,
))
)))
)(myData)))
console.log(result);
<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script>
const filter = R.filter,
flatten = R.flatten,
pipe = R.pipe,
path = R.path,
map = R.map;
const myData =
"one":
"two":
"id": "1",
"three": [
"id": "33",
"copy": [
"id": "1",
"text": "lorem",
"answer": [],
,
"id": "2",
"text": "ipsum",
"answer": [
"id": 1,
"class": "science"
]
,
"id": "3",
"text": "baesun",
"answer": [
"id": 2,
"class": "reading"
]
],
]
const result = filter(answersObj => answersObj.answers.length, flatten(pipe(
path(['one', 'two', 'three']),
map(step => step.copy.map(text => (
answers: text.answer.map(answer => (
class: answer.class,
))
)))
)(myData)))
console.log(result);
<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script>
edited Mar 27 at 1:19
answered Mar 27 at 0:33
ajai Jothiajai Jothi
1,4351 gold badge4 silver badges13 bronze badges
1,4351 gold badge4 silver badges13 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55368068%2fhow-do-i-remove-an-object-if-it-contains-a-key-with-an-empty-array%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown