Validate json single object by passing two different values with same property using underscore.jscounting object properties with underscore.jsRemove empty properties / falsy values from Object with Underscore.jsUnderscore.js - Iterating over an object and counting object propertiesUnderscore.js - get unique property valuesUnderscore.js : findWhere with nested property valuefind and replace property value in json object using javascript/underscore.jsunderscore.js find objects with same propertiesUsing underscore.js to compare two ObjectsMerge two JSON object with Underscore.jsCombine two objects that are the same in Underscore.js
Is it safe to use olive oil to clean the ear wax?
Pre-mixing cryogenic fuels and using only one fuel tank
Did arcade monitors have same pixel aspect ratio as TV sets?
Creepy dinosaur pc game identification
How to explain what's wrong with this application of the chain rule?
What will be next at the bottom row and why?
What is Cash Advance APR?
What should you do when eye contact makes your subordinate uncomfortable?
How do you make your own symbol when Detexify fails?
Redundant comparison & "if" before assignment
Why electric field inside a cavity of a non-conducting sphere not zero?
How should I respond when I lied about my education and the company finds out through background check?
Yosemite Fire Rings - What to Expect?
How can Trident be so inexpensive? Will it orbit Triton or just do a (slow) flyby?
Why did the EU agree to delay the Brexit deadline?
Is aluminum electrical wire used on aircraft?
Why a symmetric relation is defined: ∀x∀y( xRy⟹yRx) and not ∀x∀y (xRy⟺yRx)?
Does a 'pending' US visa application constitute a denial?
If a character has darkvision, can they see through an area of nonmagical darkness filled with lightly obscuring gas?
Terse Method to Swap Lowest for Highest?
Electoral considerations aside, what are potential benefits, for the US, of policy changes proposed by the tweet recognizing Golan annexation?
The screen of my macbook suddenly broken down how can I do to recover
Can I sign legal documents with a smiley face?
How much character growth crosses the line into breaking the character
Validate json single object by passing two different values with same property using underscore.js
counting object properties with underscore.jsRemove empty properties / falsy values from Object with Underscore.jsUnderscore.js - Iterating over an object and counting object propertiesUnderscore.js - get unique property valuesUnderscore.js : findWhere with nested property valuefind and replace property value in json object using javascript/underscore.jsunderscore.js find objects with same propertiesUsing underscore.js to compare two ObjectsMerge two JSON object with Underscore.jsCombine two objects that are the same in Underscore.js
Passing one json object everytime but role values changing and i need to validate it based on role using _.findWhere object using one value but i want validate with two different roles in same property.
Scenario 1
var people = [
"name": "ram", "RoleID": "2"
];
var roleObj = _.findWhere(people , RoleID: "2", RoleID: "4");
Scenario 2
var people = [
"name": "ram", "RoleID": "3"
];
var roleObj = _.findWhere(people , RoleID: "2", RoleID: "4");
In scenario 2 i should not get object why because in scound parameter not having role 3. could you please tell which _.js object i can use or what i need to change input 2nd parameter
Note: this question is scenario of in operator in sql server where we can pass multiple values in single column.
underscore.js
add a comment |
Passing one json object everytime but role values changing and i need to validate it based on role using _.findWhere object using one value but i want validate with two different roles in same property.
Scenario 1
var people = [
"name": "ram", "RoleID": "2"
];
var roleObj = _.findWhere(people , RoleID: "2", RoleID: "4");
Scenario 2
var people = [
"name": "ram", "RoleID": "3"
];
var roleObj = _.findWhere(people , RoleID: "2", RoleID: "4");
In scenario 2 i should not get object why because in scound parameter not having role 3. could you please tell which _.js object i can use or what i need to change input 2nd parameter
Note: this question is scenario of in operator in sql server where we can pass multiple values in single column.
underscore.js
ShouldRoleIdbyrole? You cannot match on both usingfindWhere, I'll add an answer which doesn't need underscore
– OliverRadini
2 days ago
1
Sorry modified question by RoleID.
– lucky
2 days ago
I've updated my answer to coverRoleId
– OliverRadini
2 days ago
add a comment |
Passing one json object everytime but role values changing and i need to validate it based on role using _.findWhere object using one value but i want validate with two different roles in same property.
Scenario 1
var people = [
"name": "ram", "RoleID": "2"
];
var roleObj = _.findWhere(people , RoleID: "2", RoleID: "4");
Scenario 2
var people = [
"name": "ram", "RoleID": "3"
];
var roleObj = _.findWhere(people , RoleID: "2", RoleID: "4");
In scenario 2 i should not get object why because in scound parameter not having role 3. could you please tell which _.js object i can use or what i need to change input 2nd parameter
Note: this question is scenario of in operator in sql server where we can pass multiple values in single column.
underscore.js
Passing one json object everytime but role values changing and i need to validate it based on role using _.findWhere object using one value but i want validate with two different roles in same property.
Scenario 1
var people = [
"name": "ram", "RoleID": "2"
];
var roleObj = _.findWhere(people , RoleID: "2", RoleID: "4");
Scenario 2
var people = [
"name": "ram", "RoleID": "3"
];
var roleObj = _.findWhere(people , RoleID: "2", RoleID: "4");
In scenario 2 i should not get object why because in scound parameter not having role 3. could you please tell which _.js object i can use or what i need to change input 2nd parameter
Note: this question is scenario of in operator in sql server where we can pass multiple values in single column.
underscore.js
underscore.js
edited 2 days ago
lucky
asked 2 days ago
luckylucky
147
147
ShouldRoleIdbyrole? You cannot match on both usingfindWhere, I'll add an answer which doesn't need underscore
– OliverRadini
2 days ago
1
Sorry modified question by RoleID.
– lucky
2 days ago
I've updated my answer to coverRoleId
– OliverRadini
2 days ago
add a comment |
ShouldRoleIdbyrole? You cannot match on both usingfindWhere, I'll add an answer which doesn't need underscore
– OliverRadini
2 days ago
1
Sorry modified question by RoleID.
– lucky
2 days ago
I've updated my answer to coverRoleId
– OliverRadini
2 days ago
Should
RoleId by role? You cannot match on both using findWhere, I'll add an answer which doesn't need underscore– OliverRadini
2 days ago
Should
RoleId by role? You cannot match on both using findWhere, I'll add an answer which doesn't need underscore– OliverRadini
2 days ago
1
1
Sorry modified question by RoleID.
– lucky
2 days ago
Sorry modified question by RoleID.
– lucky
2 days ago
I've updated my answer to cover
RoleId– OliverRadini
2 days ago
I've updated my answer to cover
RoleId– OliverRadini
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
You can do this without underscore by using filter. Simply filter out those people whose role does not appear in the list of roles specified:
var people = [
"name": "ram",
"RoleId": "3"
];
var peopleTwo = [
"name": "ram",
"RoleId": "2"
];
var getRoleFilterer = roles =>
people =>
people.filter(person => roles.indexOf(person.RoleId) > -1);
var roleFilterer = getRoleFilterer(["2", "4"]);
var results = roleFilterer(people);
var resultsTwo = roleFilterer(peopleTwo);
console.dir(results);
console.dir(resultsTwo);
Awesome solution, but I'm looking to solve by Underscore. is it not possible with it?
– lucky
2 days ago
@lucky why do you want to use Underscore when it's possible in vanilla js?
– OliverRadini
2 days ago
This application is developing using asp.net with jquery only, me only introduced underscorejs in this app.
– lucky
2 days ago
@lucky Sure - but why do you want to use underscore here? You don't need any libraries to use the code in my snippet
– OliverRadini
2 days ago
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%2f55281234%2fvalidate-json-single-object-by-passing-two-different-values-with-same-property-u%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can do this without underscore by using filter. Simply filter out those people whose role does not appear in the list of roles specified:
var people = [
"name": "ram",
"RoleId": "3"
];
var peopleTwo = [
"name": "ram",
"RoleId": "2"
];
var getRoleFilterer = roles =>
people =>
people.filter(person => roles.indexOf(person.RoleId) > -1);
var roleFilterer = getRoleFilterer(["2", "4"]);
var results = roleFilterer(people);
var resultsTwo = roleFilterer(peopleTwo);
console.dir(results);
console.dir(resultsTwo);
Awesome solution, but I'm looking to solve by Underscore. is it not possible with it?
– lucky
2 days ago
@lucky why do you want to use Underscore when it's possible in vanilla js?
– OliverRadini
2 days ago
This application is developing using asp.net with jquery only, me only introduced underscorejs in this app.
– lucky
2 days ago
@lucky Sure - but why do you want to use underscore here? You don't need any libraries to use the code in my snippet
– OliverRadini
2 days ago
add a comment |
You can do this without underscore by using filter. Simply filter out those people whose role does not appear in the list of roles specified:
var people = [
"name": "ram",
"RoleId": "3"
];
var peopleTwo = [
"name": "ram",
"RoleId": "2"
];
var getRoleFilterer = roles =>
people =>
people.filter(person => roles.indexOf(person.RoleId) > -1);
var roleFilterer = getRoleFilterer(["2", "4"]);
var results = roleFilterer(people);
var resultsTwo = roleFilterer(peopleTwo);
console.dir(results);
console.dir(resultsTwo);
Awesome solution, but I'm looking to solve by Underscore. is it not possible with it?
– lucky
2 days ago
@lucky why do you want to use Underscore when it's possible in vanilla js?
– OliverRadini
2 days ago
This application is developing using asp.net with jquery only, me only introduced underscorejs in this app.
– lucky
2 days ago
@lucky Sure - but why do you want to use underscore here? You don't need any libraries to use the code in my snippet
– OliverRadini
2 days ago
add a comment |
You can do this without underscore by using filter. Simply filter out those people whose role does not appear in the list of roles specified:
var people = [
"name": "ram",
"RoleId": "3"
];
var peopleTwo = [
"name": "ram",
"RoleId": "2"
];
var getRoleFilterer = roles =>
people =>
people.filter(person => roles.indexOf(person.RoleId) > -1);
var roleFilterer = getRoleFilterer(["2", "4"]);
var results = roleFilterer(people);
var resultsTwo = roleFilterer(peopleTwo);
console.dir(results);
console.dir(resultsTwo);You can do this without underscore by using filter. Simply filter out those people whose role does not appear in the list of roles specified:
var people = [
"name": "ram",
"RoleId": "3"
];
var peopleTwo = [
"name": "ram",
"RoleId": "2"
];
var getRoleFilterer = roles =>
people =>
people.filter(person => roles.indexOf(person.RoleId) > -1);
var roleFilterer = getRoleFilterer(["2", "4"]);
var results = roleFilterer(people);
var resultsTwo = roleFilterer(peopleTwo);
console.dir(results);
console.dir(resultsTwo);var people = [
"name": "ram",
"RoleId": "3"
];
var peopleTwo = [
"name": "ram",
"RoleId": "2"
];
var getRoleFilterer = roles =>
people =>
people.filter(person => roles.indexOf(person.RoleId) > -1);
var roleFilterer = getRoleFilterer(["2", "4"]);
var results = roleFilterer(people);
var resultsTwo = roleFilterer(peopleTwo);
console.dir(results);
console.dir(resultsTwo);var people = [
"name": "ram",
"RoleId": "3"
];
var peopleTwo = [
"name": "ram",
"RoleId": "2"
];
var getRoleFilterer = roles =>
people =>
people.filter(person => roles.indexOf(person.RoleId) > -1);
var roleFilterer = getRoleFilterer(["2", "4"]);
var results = roleFilterer(people);
var resultsTwo = roleFilterer(peopleTwo);
console.dir(results);
console.dir(resultsTwo);answered 2 days ago
OliverRadiniOliverRadini
3,113628
3,113628
Awesome solution, but I'm looking to solve by Underscore. is it not possible with it?
– lucky
2 days ago
@lucky why do you want to use Underscore when it's possible in vanilla js?
– OliverRadini
2 days ago
This application is developing using asp.net with jquery only, me only introduced underscorejs in this app.
– lucky
2 days ago
@lucky Sure - but why do you want to use underscore here? You don't need any libraries to use the code in my snippet
– OliverRadini
2 days ago
add a comment |
Awesome solution, but I'm looking to solve by Underscore. is it not possible with it?
– lucky
2 days ago
@lucky why do you want to use Underscore when it's possible in vanilla js?
– OliverRadini
2 days ago
This application is developing using asp.net with jquery only, me only introduced underscorejs in this app.
– lucky
2 days ago
@lucky Sure - but why do you want to use underscore here? You don't need any libraries to use the code in my snippet
– OliverRadini
2 days ago
Awesome solution, but I'm looking to solve by Underscore. is it not possible with it?
– lucky
2 days ago
Awesome solution, but I'm looking to solve by Underscore. is it not possible with it?
– lucky
2 days ago
@lucky why do you want to use Underscore when it's possible in vanilla js?
– OliverRadini
2 days ago
@lucky why do you want to use Underscore when it's possible in vanilla js?
– OliverRadini
2 days ago
This application is developing using asp.net with jquery only, me only introduced underscorejs in this app.
– lucky
2 days ago
This application is developing using asp.net with jquery only, me only introduced underscorejs in this app.
– lucky
2 days ago
@lucky Sure - but why do you want to use underscore here? You don't need any libraries to use the code in my snippet
– OliverRadini
2 days ago
@lucky Sure - but why do you want to use underscore here? You don't need any libraries to use the code in my snippet
– OliverRadini
2 days ago
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%2f55281234%2fvalidate-json-single-object-by-passing-two-different-values-with-same-property-u%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
Should
RoleIdbyrole? You cannot match on both usingfindWhere, I'll add an answer which doesn't need underscore– OliverRadini
2 days ago
1
Sorry modified question by RoleID.
– lucky
2 days ago
I've updated my answer to cover
RoleId– OliverRadini
2 days ago