Performing delete operations on an immutable JS Map object
I have an immutable JS map with a structure like the below
{
"a": [
{"name": "foo", "untracked": true},
{"name": "bar"}
],
"b": [
{"name": "baz"},
{"name": "bar", "untracked": true}
]
}
I want to filter this object to only show objects which are tracked - i.e
{
"a": [
{"name": "bar"}
],
"b": [
{"name": "baz"},
]
}
Is there a way for me to do this with immutable map operations? i tried the below but it doesnt seem to work
object.map((lis) => lis.filter((li) => li.untracked !== true)).toJS()
object.toList().map((lis) => lis.filter((li) => li.untracked !== true))
javascript immutable.js
add a comment |
I have an immutable JS map with a structure like the below
{
"a": [
{"name": "foo", "untracked": true},
{"name": "bar"}
],
"b": [
{"name": "baz"},
{"name": "bar", "untracked": true}
]
}
I want to filter this object to only show objects which are tracked - i.e
{
"a": [
{"name": "bar"}
],
"b": [
{"name": "baz"},
]
}
Is there a way for me to do this with immutable map operations? i tried the below but it doesnt seem to work
object.map((lis) => lis.filter((li) => li.untracked !== true)).toJS()
object.toList().map((lis) => lis.filter((li) => li.untracked !== true))
javascript immutable.js
add a comment |
I have an immutable JS map with a structure like the below
{
"a": [
{"name": "foo", "untracked": true},
{"name": "bar"}
],
"b": [
{"name": "baz"},
{"name": "bar", "untracked": true}
]
}
I want to filter this object to only show objects which are tracked - i.e
{
"a": [
{"name": "bar"}
],
"b": [
{"name": "baz"},
]
}
Is there a way for me to do this with immutable map operations? i tried the below but it doesnt seem to work
object.map((lis) => lis.filter((li) => li.untracked !== true)).toJS()
object.toList().map((lis) => lis.filter((li) => li.untracked !== true))
javascript immutable.js
I have an immutable JS map with a structure like the below
{
"a": [
{"name": "foo", "untracked": true},
{"name": "bar"}
],
"b": [
{"name": "baz"},
{"name": "bar", "untracked": true}
]
}
I want to filter this object to only show objects which are tracked - i.e
{
"a": [
{"name": "bar"}
],
"b": [
{"name": "baz"},
]
}
Is there a way for me to do this with immutable map operations? i tried the below but it doesnt seem to work
object.map((lis) => lis.filter((li) => li.untracked !== true)).toJS()
object.toList().map((lis) => lis.filter((li) => li.untracked !== true))
javascript immutable.js
javascript immutable.js
asked Nov 20 '18 at 16:30
KannajKannaj
2,04521641
2,04521641
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
let data={
"a": [
{"name": "foo", "untracked": true},
{"name": "bar"}
],
"b": [
{"name": "baz"},
{"name": "bar", "untracked": true}
]
}
Object.entries(data).map(([key, value]) => {
data[key]=value.filter(ele=>ele.untracked!=true)
});
console.log("result is : ",data)
add a comment |
As per ImmutableJS docs:
filter() returns a new Map with only the entries for which the predicate function returns true.
example:
function someFilterFunction(entry) {
return !entry.untracked;
}
myMapOfStuff = myMapOfStuff.filter(someFilterFunction);
Link to documentation: https://facebook.github.io/immutable-js/docs/#/Map/filter
EDIT: Remember, the method on an immutable collection returns a COPY of the collection you are operating on. A reassignment must happen if you want to preserve the most up to date reference.
add a comment |
Loop through that object and create a new object with keys from old object and then filter the values from the old object where untracked is not equal to false
let obj = {
"a": [{
"name": "foo",
"untracked": true
},
{
"name": "bar"
}
],
"b": [{
"name": "baz"
},
{
"name": "bar",
"untracked": true
}
]
}
let newObj = {};
function filterObject(obj) {
for (let keys in obj) {
newObj[keys] = obj[keys].filter(item => {
return item.untracked !== true
})
}
}
filterObject(obj)
console.log(newObj)
add a comment |
data = {
"a": [
{"name": "foo", "untracked": true},
{"name": "bar"}
],
"b": [
{"name": "baz"},
{"name": "bar", "untracked": true}
]
}
let result = Object.entries(data).map(([key, values])=>(
{ key: values.filter(({untracked})=> !untracked) }
))
console.log(result)
Uncaught ReferenceError: result is not defined. Also you are changing the structure of the given data as output will be=> [ { "key": [ { "name": "bar" } ] }, { "key": [ { "name": "baz" } ] } ]
– Monica Acha
Nov 20 '18 at 17:40
I forgot to declare the result variable.Thanks @Monic
– Mohammed Ashfaq
Nov 21 '18 at 1:23
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%2f53397409%2fperforming-delete-operations-on-an-immutable-js-map-object%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
let data={
"a": [
{"name": "foo", "untracked": true},
{"name": "bar"}
],
"b": [
{"name": "baz"},
{"name": "bar", "untracked": true}
]
}
Object.entries(data).map(([key, value]) => {
data[key]=value.filter(ele=>ele.untracked!=true)
});
console.log("result is : ",data)
add a comment |
let data={
"a": [
{"name": "foo", "untracked": true},
{"name": "bar"}
],
"b": [
{"name": "baz"},
{"name": "bar", "untracked": true}
]
}
Object.entries(data).map(([key, value]) => {
data[key]=value.filter(ele=>ele.untracked!=true)
});
console.log("result is : ",data)
add a comment |
let data={
"a": [
{"name": "foo", "untracked": true},
{"name": "bar"}
],
"b": [
{"name": "baz"},
{"name": "bar", "untracked": true}
]
}
Object.entries(data).map(([key, value]) => {
data[key]=value.filter(ele=>ele.untracked!=true)
});
console.log("result is : ",data)
let data={
"a": [
{"name": "foo", "untracked": true},
{"name": "bar"}
],
"b": [
{"name": "baz"},
{"name": "bar", "untracked": true}
]
}
Object.entries(data).map(([key, value]) => {
data[key]=value.filter(ele=>ele.untracked!=true)
});
console.log("result is : ",data)
let data={
"a": [
{"name": "foo", "untracked": true},
{"name": "bar"}
],
"b": [
{"name": "baz"},
{"name": "bar", "untracked": true}
]
}
Object.entries(data).map(([key, value]) => {
data[key]=value.filter(ele=>ele.untracked!=true)
});
console.log("result is : ",data)
let data={
"a": [
{"name": "foo", "untracked": true},
{"name": "bar"}
],
"b": [
{"name": "baz"},
{"name": "bar", "untracked": true}
]
}
Object.entries(data).map(([key, value]) => {
data[key]=value.filter(ele=>ele.untracked!=true)
});
console.log("result is : ",data)
edited Nov 20 '18 at 17:05
answered Nov 20 '18 at 16:59
BittuSBittuS
587216
587216
add a comment |
add a comment |
As per ImmutableJS docs:
filter() returns a new Map with only the entries for which the predicate function returns true.
example:
function someFilterFunction(entry) {
return !entry.untracked;
}
myMapOfStuff = myMapOfStuff.filter(someFilterFunction);
Link to documentation: https://facebook.github.io/immutable-js/docs/#/Map/filter
EDIT: Remember, the method on an immutable collection returns a COPY of the collection you are operating on. A reassignment must happen if you want to preserve the most up to date reference.
add a comment |
As per ImmutableJS docs:
filter() returns a new Map with only the entries for which the predicate function returns true.
example:
function someFilterFunction(entry) {
return !entry.untracked;
}
myMapOfStuff = myMapOfStuff.filter(someFilterFunction);
Link to documentation: https://facebook.github.io/immutable-js/docs/#/Map/filter
EDIT: Remember, the method on an immutable collection returns a COPY of the collection you are operating on. A reassignment must happen if you want to preserve the most up to date reference.
add a comment |
As per ImmutableJS docs:
filter() returns a new Map with only the entries for which the predicate function returns true.
example:
function someFilterFunction(entry) {
return !entry.untracked;
}
myMapOfStuff = myMapOfStuff.filter(someFilterFunction);
Link to documentation: https://facebook.github.io/immutable-js/docs/#/Map/filter
EDIT: Remember, the method on an immutable collection returns a COPY of the collection you are operating on. A reassignment must happen if you want to preserve the most up to date reference.
As per ImmutableJS docs:
filter() returns a new Map with only the entries for which the predicate function returns true.
example:
function someFilterFunction(entry) {
return !entry.untracked;
}
myMapOfStuff = myMapOfStuff.filter(someFilterFunction);
Link to documentation: https://facebook.github.io/immutable-js/docs/#/Map/filter
EDIT: Remember, the method on an immutable collection returns a COPY of the collection you are operating on. A reassignment must happen if you want to preserve the most up to date reference.
answered Nov 20 '18 at 16:35
Francisco GarciaFrancisco Garcia
704
704
add a comment |
add a comment |
Loop through that object and create a new object with keys from old object and then filter the values from the old object where untracked is not equal to false
let obj = {
"a": [{
"name": "foo",
"untracked": true
},
{
"name": "bar"
}
],
"b": [{
"name": "baz"
},
{
"name": "bar",
"untracked": true
}
]
}
let newObj = {};
function filterObject(obj) {
for (let keys in obj) {
newObj[keys] = obj[keys].filter(item => {
return item.untracked !== true
})
}
}
filterObject(obj)
console.log(newObj)
add a comment |
Loop through that object and create a new object with keys from old object and then filter the values from the old object where untracked is not equal to false
let obj = {
"a": [{
"name": "foo",
"untracked": true
},
{
"name": "bar"
}
],
"b": [{
"name": "baz"
},
{
"name": "bar",
"untracked": true
}
]
}
let newObj = {};
function filterObject(obj) {
for (let keys in obj) {
newObj[keys] = obj[keys].filter(item => {
return item.untracked !== true
})
}
}
filterObject(obj)
console.log(newObj)
add a comment |
Loop through that object and create a new object with keys from old object and then filter the values from the old object where untracked is not equal to false
let obj = {
"a": [{
"name": "foo",
"untracked": true
},
{
"name": "bar"
}
],
"b": [{
"name": "baz"
},
{
"name": "bar",
"untracked": true
}
]
}
let newObj = {};
function filterObject(obj) {
for (let keys in obj) {
newObj[keys] = obj[keys].filter(item => {
return item.untracked !== true
})
}
}
filterObject(obj)
console.log(newObj)
Loop through that object and create a new object with keys from old object and then filter the values from the old object where untracked is not equal to false
let obj = {
"a": [{
"name": "foo",
"untracked": true
},
{
"name": "bar"
}
],
"b": [{
"name": "baz"
},
{
"name": "bar",
"untracked": true
}
]
}
let newObj = {};
function filterObject(obj) {
for (let keys in obj) {
newObj[keys] = obj[keys].filter(item => {
return item.untracked !== true
})
}
}
filterObject(obj)
console.log(newObj)
let obj = {
"a": [{
"name": "foo",
"untracked": true
},
{
"name": "bar"
}
],
"b": [{
"name": "baz"
},
{
"name": "bar",
"untracked": true
}
]
}
let newObj = {};
function filterObject(obj) {
for (let keys in obj) {
newObj[keys] = obj[keys].filter(item => {
return item.untracked !== true
})
}
}
filterObject(obj)
console.log(newObj)
let obj = {
"a": [{
"name": "foo",
"untracked": true
},
{
"name": "bar"
}
],
"b": [{
"name": "baz"
},
{
"name": "bar",
"untracked": true
}
]
}
let newObj = {};
function filterObject(obj) {
for (let keys in obj) {
newObj[keys] = obj[keys].filter(item => {
return item.untracked !== true
})
}
}
filterObject(obj)
console.log(newObj)
answered Nov 20 '18 at 16:37
brkbrk
26.5k31940
26.5k31940
add a comment |
add a comment |
data = {
"a": [
{"name": "foo", "untracked": true},
{"name": "bar"}
],
"b": [
{"name": "baz"},
{"name": "bar", "untracked": true}
]
}
let result = Object.entries(data).map(([key, values])=>(
{ key: values.filter(({untracked})=> !untracked) }
))
console.log(result)
Uncaught ReferenceError: result is not defined. Also you are changing the structure of the given data as output will be=> [ { "key": [ { "name": "bar" } ] }, { "key": [ { "name": "baz" } ] } ]
– Monica Acha
Nov 20 '18 at 17:40
I forgot to declare the result variable.Thanks @Monic
– Mohammed Ashfaq
Nov 21 '18 at 1:23
add a comment |
data = {
"a": [
{"name": "foo", "untracked": true},
{"name": "bar"}
],
"b": [
{"name": "baz"},
{"name": "bar", "untracked": true}
]
}
let result = Object.entries(data).map(([key, values])=>(
{ key: values.filter(({untracked})=> !untracked) }
))
console.log(result)
Uncaught ReferenceError: result is not defined. Also you are changing the structure of the given data as output will be=> [ { "key": [ { "name": "bar" } ] }, { "key": [ { "name": "baz" } ] } ]
– Monica Acha
Nov 20 '18 at 17:40
I forgot to declare the result variable.Thanks @Monic
– Mohammed Ashfaq
Nov 21 '18 at 1:23
add a comment |
data = {
"a": [
{"name": "foo", "untracked": true},
{"name": "bar"}
],
"b": [
{"name": "baz"},
{"name": "bar", "untracked": true}
]
}
let result = Object.entries(data).map(([key, values])=>(
{ key: values.filter(({untracked})=> !untracked) }
))
console.log(result)
data = {
"a": [
{"name": "foo", "untracked": true},
{"name": "bar"}
],
"b": [
{"name": "baz"},
{"name": "bar", "untracked": true}
]
}
let result = Object.entries(data).map(([key, values])=>(
{ key: values.filter(({untracked})=> !untracked) }
))
console.log(result)
data = {
"a": [
{"name": "foo", "untracked": true},
{"name": "bar"}
],
"b": [
{"name": "baz"},
{"name": "bar", "untracked": true}
]
}
let result = Object.entries(data).map(([key, values])=>(
{ key: values.filter(({untracked})=> !untracked) }
))
console.log(result)
data = {
"a": [
{"name": "foo", "untracked": true},
{"name": "bar"}
],
"b": [
{"name": "baz"},
{"name": "bar", "untracked": true}
]
}
let result = Object.entries(data).map(([key, values])=>(
{ key: values.filter(({untracked})=> !untracked) }
))
console.log(result)
edited Nov 21 '18 at 1:21
answered Nov 20 '18 at 17:14


Mohammed AshfaqMohammed Ashfaq
1,6672612
1,6672612
Uncaught ReferenceError: result is not defined. Also you are changing the structure of the given data as output will be=> [ { "key": [ { "name": "bar" } ] }, { "key": [ { "name": "baz" } ] } ]
– Monica Acha
Nov 20 '18 at 17:40
I forgot to declare the result variable.Thanks @Monic
– Mohammed Ashfaq
Nov 21 '18 at 1:23
add a comment |
Uncaught ReferenceError: result is not defined. Also you are changing the structure of the given data as output will be=> [ { "key": [ { "name": "bar" } ] }, { "key": [ { "name": "baz" } ] } ]
– Monica Acha
Nov 20 '18 at 17:40
I forgot to declare the result variable.Thanks @Monic
– Mohammed Ashfaq
Nov 21 '18 at 1:23
Uncaught ReferenceError: result is not defined. Also you are changing the structure of the given data as output will be=> [ { "key": [ { "name": "bar" } ] }, { "key": [ { "name": "baz" } ] } ]
– Monica Acha
Nov 20 '18 at 17:40
Uncaught ReferenceError: result is not defined. Also you are changing the structure of the given data as output will be=> [ { "key": [ { "name": "bar" } ] }, { "key": [ { "name": "baz" } ] } ]
– Monica Acha
Nov 20 '18 at 17:40
I forgot to declare the result variable.Thanks @Monic
– Mohammed Ashfaq
Nov 21 '18 at 1:23
I forgot to declare the result variable.Thanks @Monic
– Mohammed Ashfaq
Nov 21 '18 at 1:23
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%2f53397409%2fperforming-delete-operations-on-an-immutable-js-map-object%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