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













0















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.










share|improve this question
























  • 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





    Sorry modified question by RoleID.

    – lucky
    2 days ago











  • I've updated my answer to cover RoleId

    – OliverRadini
    2 days ago















0















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.










share|improve this question
























  • 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





    Sorry modified question by RoleID.

    – lucky
    2 days ago











  • I've updated my answer to cover RoleId

    – OliverRadini
    2 days ago













0












0








0








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago







lucky

















asked 2 days ago









luckylucky

147




147












  • 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





    Sorry modified question by RoleID.

    – lucky
    2 days ago











  • I've updated my answer to cover RoleId

    – 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





    Sorry modified question by RoleID.

    – lucky
    2 days ago











  • I've updated my answer to cover RoleId

    – 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












1 Answer
1






active

oldest

votes


















0














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);








share|improve this answer























  • 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










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
);



);













draft saved

draft discarded


















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









0














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);








share|improve this answer























  • 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















0














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);








share|improve this answer























  • 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













0












0








0







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);








share|improve this answer













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);






share|improve this answer












share|improve this answer



share|improve this answer










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

















  • 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



















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해