Compare two arrays diferent lengthLength of a JavaScript objectHow do I check if an array includes an object in JavaScript?How to append something to an array?Compare two dates with JavaScriptHow to insert an item into an array at a specific index (JavaScript)?How do I empty an array in JavaScript?Loop through an array in JavaScriptHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?

co-son-in-law or co-brother

Is there any reason to change the ISO manually?

If I have an accident, should I file a claim with my car insurance company?

Which is the best password hashing algorithm in .NET Core?

Why did the VIC-II and SID use 6 µm technology in the era of 3 µm and 1.5 µm?

How do I name the individual parts of the lumbricals muscle of the foot in latin?

Go for an isolated pawn

How can I let authenticated users rebuild caches?

Plotting level sets of the form f(x,y,c)==0

Generate points for smooth movement between two given points

The little bee buzzes around the flower garden

Short story with a first person narrator in a future where racial conflict had exploded into an all out war

What's the difference between a share and a stock?

What happens when there is no available physical memory left for SQL Server?

How could a planet have one hemisphere way warmer than the other without the planet being tidally locked?

Real-world issues with using an alias

How did Gollum know Sauron was gathering the Haradrim to make war?

When making yogurt, why doesn't bad bacteria grow as well?

How do you manage to study and have a balance in your life at the same time?

What does "se jouer" mean here?

Why would a Intel 8080 chip be destroyed if +12 V is connected before -5 V?

Has Rey's new lightsaber been seen before in canon or legends?

Archiving processor does not archive

IEEE Registration Authority mac prefix



Compare two arrays diferent length


Length of a JavaScript objectHow do I check if an array includes an object in JavaScript?How to append something to an array?Compare two dates with JavaScriptHow to insert an item into an array at a specific index (JavaScript)?How do I empty an array in JavaScript?Loop through an array in JavaScriptHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have 2 arrays in jade, with different length sizes I just want to validate if the id is the same so that those are selected and the others are not



 // jsCategory length 6
var jsCategory = array1
// jsCategory length 3
var jsMy = array2

var html_option = '';

for (var i = 0; i < jsCategory.length; i++)

for (var z = 0; z < jsMy.length; z++)
if (jsCategory[i]._id == jsMy[z]._id)
//Correct
html_option += '<option value=' + jsCategory[i]._id + ' selected>' + jsCategory[i].name + '</option>';
else
//Not Select err
console.log(jsCategory[i]);




document.write(html_option);









share|improve this question


























  • Looks like you have almost got it right. Just break out of the inner loop when you have success, after html_option += line, add break;

    – Programnik
    Mar 28 at 2:44






  • 1





    But what is the error?

    – bird
    Mar 28 at 3:06

















0















I have 2 arrays in jade, with different length sizes I just want to validate if the id is the same so that those are selected and the others are not



 // jsCategory length 6
var jsCategory = array1
// jsCategory length 3
var jsMy = array2

var html_option = '';

for (var i = 0; i < jsCategory.length; i++)

for (var z = 0; z < jsMy.length; z++)
if (jsCategory[i]._id == jsMy[z]._id)
//Correct
html_option += '<option value=' + jsCategory[i]._id + ' selected>' + jsCategory[i].name + '</option>';
else
//Not Select err
console.log(jsCategory[i]);




document.write(html_option);









share|improve this question


























  • Looks like you have almost got it right. Just break out of the inner loop when you have success, after html_option += line, add break;

    – Programnik
    Mar 28 at 2:44






  • 1





    But what is the error?

    – bird
    Mar 28 at 3:06













0












0








0








I have 2 arrays in jade, with different length sizes I just want to validate if the id is the same so that those are selected and the others are not



 // jsCategory length 6
var jsCategory = array1
// jsCategory length 3
var jsMy = array2

var html_option = '';

for (var i = 0; i < jsCategory.length; i++)

for (var z = 0; z < jsMy.length; z++)
if (jsCategory[i]._id == jsMy[z]._id)
//Correct
html_option += '<option value=' + jsCategory[i]._id + ' selected>' + jsCategory[i].name + '</option>';
else
//Not Select err
console.log(jsCategory[i]);




document.write(html_option);









share|improve this question
















I have 2 arrays in jade, with different length sizes I just want to validate if the id is the same so that those are selected and the others are not



 // jsCategory length 6
var jsCategory = array1
// jsCategory length 3
var jsMy = array2

var html_option = '';

for (var i = 0; i < jsCategory.length; i++)

for (var z = 0; z < jsMy.length; z++)
if (jsCategory[i]._id == jsMy[z]._id)
//Correct
html_option += '<option value=' + jsCategory[i]._id + ' selected>' + jsCategory[i].name + '</option>';
else
//Not Select err
console.log(jsCategory[i]);




document.write(html_option);






javascript






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 2:37









Obsidian Age

31.2k7 gold badges27 silver badges48 bronze badges




31.2k7 gold badges27 silver badges48 bronze badges










asked Mar 28 at 2:36









Edinson Carranza SaldañaEdinson Carranza Saldaña

12 bronze badges




12 bronze badges















  • Looks like you have almost got it right. Just break out of the inner loop when you have success, after html_option += line, add break;

    – Programnik
    Mar 28 at 2:44






  • 1





    But what is the error?

    – bird
    Mar 28 at 3:06

















  • Looks like you have almost got it right. Just break out of the inner loop when you have success, after html_option += line, add break;

    – Programnik
    Mar 28 at 2:44






  • 1





    But what is the error?

    – bird
    Mar 28 at 3:06
















Looks like you have almost got it right. Just break out of the inner loop when you have success, after html_option += line, add break;

– Programnik
Mar 28 at 2:44





Looks like you have almost got it right. Just break out of the inner loop when you have success, after html_option += line, add break;

– Programnik
Mar 28 at 2:44




1




1





But what is the error?

– bird
Mar 28 at 3:06





But what is the error?

– bird
Mar 28 at 3:06












1 Answer
1






active

oldest

votes


















0
















It's shorter to use filter and reduce



const findById = inWhere => ( _id ) => !!inWhere.find(t => t._id === _id)

const html_option = array1
.filter(findById(array2))
.reduce((html, (_id, name) =>
html += `<option value=$_id selected>$name</option>`, ''))





share|improve this answer



























  • missing ) after argument list

    – Edinson Carranza Saldaña
    Mar 28 at 18:27











  • @EdinsonCarranzaSaldaña thanks!

    – dehumanizer
    Mar 28 at 23:13










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%2f55389365%2fcompare-two-arrays-diferent-length%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
















It's shorter to use filter and reduce



const findById = inWhere => ( _id ) => !!inWhere.find(t => t._id === _id)

const html_option = array1
.filter(findById(array2))
.reduce((html, (_id, name) =>
html += `<option value=$_id selected>$name</option>`, ''))





share|improve this answer



























  • missing ) after argument list

    – Edinson Carranza Saldaña
    Mar 28 at 18:27











  • @EdinsonCarranzaSaldaña thanks!

    – dehumanizer
    Mar 28 at 23:13















0
















It's shorter to use filter and reduce



const findById = inWhere => ( _id ) => !!inWhere.find(t => t._id === _id)

const html_option = array1
.filter(findById(array2))
.reduce((html, (_id, name) =>
html += `<option value=$_id selected>$name</option>`, ''))





share|improve this answer



























  • missing ) after argument list

    – Edinson Carranza Saldaña
    Mar 28 at 18:27











  • @EdinsonCarranzaSaldaña thanks!

    – dehumanizer
    Mar 28 at 23:13













0














0










0









It's shorter to use filter and reduce



const findById = inWhere => ( _id ) => !!inWhere.find(t => t._id === _id)

const html_option = array1
.filter(findById(array2))
.reduce((html, (_id, name) =>
html += `<option value=$_id selected>$name</option>`, ''))





share|improve this answer















It's shorter to use filter and reduce



const findById = inWhere => ( _id ) => !!inWhere.find(t => t._id === _id)

const html_option = array1
.filter(findById(array2))
.reduce((html, (_id, name) =>
html += `<option value=$_id selected>$name</option>`, ''))






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 28 at 23:13

























answered Mar 28 at 4:19









dehumanizerdehumanizer

5024 silver badges12 bronze badges




5024 silver badges12 bronze badges















  • missing ) after argument list

    – Edinson Carranza Saldaña
    Mar 28 at 18:27











  • @EdinsonCarranzaSaldaña thanks!

    – dehumanizer
    Mar 28 at 23:13

















  • missing ) after argument list

    – Edinson Carranza Saldaña
    Mar 28 at 18:27











  • @EdinsonCarranzaSaldaña thanks!

    – dehumanizer
    Mar 28 at 23:13
















missing ) after argument list

– Edinson Carranza Saldaña
Mar 28 at 18:27





missing ) after argument list

– Edinson Carranza Saldaña
Mar 28 at 18:27













@EdinsonCarranzaSaldaña thanks!

– dehumanizer
Mar 28 at 23:13





@EdinsonCarranzaSaldaña thanks!

– dehumanizer
Mar 28 at 23:13








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















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%2f55389365%2fcompare-two-arrays-diferent-length%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

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

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

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현